module mod_clm_cnsummary
#ifdef CN
  !
  ! Module for carbon and nitrogen summary calculations
  !
  use mod_stdio
  use mod_intkinds
  use mod_realkinds
  use mod_mpmessage
  use mod_runparams, only : dtsrf
  use mod_clm_varcon, only: dzsoi_decomp, zisoi
  use mod_clm_pftvarcon  , only: npcropmin
  use mod_clm_surfrd  , only: crop_prog

  implicit none

  save

  private

  public :: CSummary
  public :: NSummary

  contains
  !
  ! On the radiation time step, perform pft and column-level carbon
  ! summary calculations
  !
  subroutine CSummary(num_soilc, filter_soilc, num_soilp, filter_soilp, isotope)
    use mod_clm_type
    use mod_clm_subgridave, only : p2c
    use mod_clm_varpar, only : nlevdecomp, ndecomp_pools, &
            ndecomp_cascade_transitions
    use mod_clm_cnndynamics, only : nfix_timeconst
    use mod_clm_varcon, only : secspday, spval
    implicit none
    integer(ik4), intent(in) :: num_soilc ! number of soil columns in filter
    integer(ik4), intent(in) :: filter_soilc(:) ! filter for soil columns
    integer(ik4), intent(in) :: num_soilp       ! number of soil pfts in filter
    integer(ik4), intent(in) :: filter_soilp(:) ! filter for soil pfts
    character(len=*), intent(in) :: isotope     ! 'bulk', 'c13' or 'c14'

    integer(ik4), pointer, contiguous :: ivt(:)            ! pft vegetation type
    ! (gC/m2/s) total column-level fire C loss
    real(rk8), pointer, contiguous :: col_fire_closs(:)
    ! (gC/m2/s) total ecosystem respiration, autotrophic + heterotrophic
    real(rk8), pointer, contiguous :: er(:)
    ! (gC/m2/s) total heterotrophic respiration
    real(rk8), pointer, contiguous :: hr(:)
    real(rk8), pointer, contiguous :: litfire(:)  ! (gC/m2/s) litter fire losses
    real(rk8), pointer, contiguous :: lithr(:) ! (gC/m2/s) litter heterotrophic respiration
    real(rk8), pointer, contiguous :: cwdc(:)  ! (gC/m2) coarse woody debris C
    ! (gC/m2) column-level sink for C truncation
    real(rk8), pointer, contiguous :: col_ctrunc(:)
    real(rk8), pointer, contiguous :: decomp_cascade_hr_vr(:,:,:)
    real(rk8), pointer, contiguous :: decomp_cascade_hr(:,:)
    ! total vertically-resolved het. resp. from decomposing C pools (gC/m3/s)
    real(rk8), pointer, contiguous :: hr_vr(:,:)
    real(rk8), pointer, contiguous :: m_decomp_cpools_to_fire_vr(:,:,:)
    real(rk8), pointer, contiguous :: m_decomp_cpools_to_fire(:,:)

    ! (gC/m2)  decomposing (litter, cwd, soil) c pools
    real(rk8), pointer, contiguous :: decomp_cpools(:,:)
    ! (gC/m2)  decomposing (litter, cwd, soil) c pools to 1 meter
    real(rk8), pointer, contiguous :: decomp_cpools_1m(:,:)
    ! (gC/m3)  vertically-resolved decomposing (litter, cwd, soil) c pools
    real(rk8), pointer, contiguous :: decomp_cpools_vr(:,:,:)
    ! maximum annual depth of thaw
    integer(ik4), pointer, contiguous :: altmax_indx(:)
    ! prior year maximum annual depth of thaw
    integer(ik4), pointer, contiguous :: altmax_lastyear_indx(:)
    ! (gC/m3) column-level sink for C truncation
    real(rk8), pointer, contiguous :: col_ctrunc_vr(:,:)
    ! which pool is C taken from for a given decomposition step
    integer(ik4),  pointer, contiguous :: cascade_donor_pool(:)
    logical, pointer, contiguous :: is_litter(:) ! TRUE => pool is a litter pool
    logical, pointer, contiguous :: is_soil(:)   ! TRUE => pool is a soil pool
    logical, pointer, contiguous :: is_cwd(:)    ! TRUE => pool is a cwd pool
    ! (gC/m2/s) net ecosystem exchange of carbon, includes fire, land-use,
    ! harvest, and hrv_xsmrpool flux, positive for source
    real(rk8), pointer, contiguous :: nee(:)
    ! (gC/m2/s) net ecosystem production, excludes fire, land-use,
    ! and harvest flux, positive for sink
    real(rk8), pointer, contiguous :: nep(:)
    ! (gC/m2/s) net biome production, includes fire, land-use,
    ! and harvest flux, positive for sink
    real(rk8), pointer, contiguous :: nbp(:)
    ! (gC/m2/s) autotrophic respiration (MR + GR)
    real(rk8), pointer, contiguous :: col_ar(:)
    ! GPP flux before downregulation (gC/m2/s)
    real(rk8), pointer, contiguous :: col_gpp(:)
    ! (gC/m2/s) net primary production
    real(rk8), pointer, contiguous :: col_npp(:)
    ! (gC/m2/s) lagged net primary production
    real(rk8), pointer, contiguous :: col_lag_npp(:)
    ! (gC/m2/s) total pft-level fire C loss
    real(rk8), pointer, contiguous :: col_pft_fire_closs(:)
    ! (gC/m2/s) total pft-level litterfall C loss
    real(rk8), pointer, contiguous :: col_litfall(:)
    ! (gC/m2/s) root respiration (fine root MR + total root GR)
    real(rk8), pointer, contiguous :: col_rr(:)
    ! (gC/m2/s) pft-level fire loss (obsolete, mark for removal)
    real(rk8), pointer, contiguous :: col_vegfire(:)
    real(rk8), pointer, contiguous :: col_wood_harvestc(:)
    ! (gC/m2/s) soil organic matter fire losses
    real(rk8), pointer, contiguous :: somfire(:)
    ! (gC/m2/s) soil organic matter heterotrophic respiration
    real(rk8), pointer, contiguous :: somhr(:)
    ! (gC/m2/s) total soil respiration (HR + root resp)
    real(rk8), pointer, contiguous :: sr(:)
    ! (gC/m2/s) total ecosystem fire losses
    real(rk8), pointer, contiguous :: totfire(:)
    ! (gC/m2) total pft-level carbon, including cpool
    real(rk8), pointer, contiguous :: col_totpftc(:)
    ! (gC/m2) total vegetation carbon, excluding cpool
    real(rk8), pointer, contiguous :: col_totvegc(:)
    ! (gC/m2) total column carbon, incl veg and cpool
    real(rk8), pointer, contiguous :: totcolc(:)
    ! (gC/m2) total ecosystem carbon, incl veg but excl cpool
    real(rk8), pointer, contiguous :: totecosysc(:)
    real(rk8), pointer, contiguous :: totlitc(:)    ! (gC/m2) total litter carbon
    real(rk8), pointer, contiguous :: totlitc_1m(:) ! (gC/m2) total litter carbon to 1 meter
    real(rk8), pointer, contiguous :: totsomc(:)  ! (gC/m2) total soil organic matter carbon
    ! (gC/m2) total soil organic matter carbon to 1 meter
    real(rk8), pointer, contiguous :: totsomc_1m(:)
    real(rk8), pointer, contiguous :: agnpp(:) ! (gC/m2/s) aboveground NPP
    real(rk8), pointer, contiguous :: ar(:)    ! (gC/m2/s) autotrophic respiration (MR + GR)
    real(rk8), pointer, contiguous :: bgnpp(:) ! (gC/m2/s) belowground NPP
    ! excess MR pool harvest mortality (gC/m2/s)
    real(rk8), pointer, contiguous :: xsmrpool_to_atm(:)
    ! grain growth respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_grain_gr(:)
    ! grain growth respiration to storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_grain_storage_gr(:)
    ! allocation to grain C storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_to_grainc(:)
    ! grain C growth from storage (gC/m2/s)
    real(rk8), pointer, contiguous :: grainc_xfer_to_grainc(:)
    ! grain growth respiration from storage (gC/m2/s)
    real(rk8), pointer, contiguous :: transfer_grain_gr(:)
    ! grain C to food (gC/m2/s)
    real(rk8), pointer, contiguous :: grainc_to_food(:)
    ! live stem C litterfall (gC/m2/s)
    real(rk8), pointer, contiguous :: livestemc_to_litter(:)
    real(rk8), pointer, contiguous :: grainc(:)             ! (gC/m2) grain C
    real(rk8), pointer, contiguous :: grainc_storage(:)     ! (gC/m2) grain C storage
    real(rk8), pointer, contiguous :: grainc_xfer(:)        ! (gC/m2) grain C transfer
    ! dead coarse root growth respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_deadcroot_gr(:)
    ! dead coarse root growth respiration to storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_deadcroot_storage_gr(:)
    ! dead stem growth respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_deadstem_gr(:)
    ! dead stem growth respiration to storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_deadstem_storage_gr(:)
    ! fine root growth respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_froot_gr(:)
    ! fine root  growth respiration to storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_froot_storage_gr(:)
    ! leaf growth respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_leaf_gr(:)
    ! leaf growth respiration to storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_leaf_storage_gr(:)
    ! live coarse root growth respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_livecroot_gr(:)
    ! live coarse root growth respiration to storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_livecroot_storage_gr(:)
    ! live stem growth respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_livestem_gr(:)
    ! live stem growth respiration to storage (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_livestem_storage_gr(:)
    ! allocation to dead coarse root C (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_to_deadcrootc(:)
    ! allocation to dead stem C (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_to_deadstemc(:)
    ! allocation to fine root C (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_to_frootc(:)
    ! allocation to leaf C (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_to_leafc(:)
    ! allocation to live coarse root C (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_to_livecrootc(:)
    ! allocation to live stem C (gC/m2/s)
    real(rk8), pointer, contiguous :: cpool_to_livestemc(:)
    ! (gC/m2/s) growth resp for new growth displayed in this timestep
    real(rk8), pointer, contiguous :: current_gr(:)
    real(rk8), pointer, contiguous :: deadcrootc_xfer_to_deadcrootc(:)
    real(rk8), pointer, contiguous :: deadstemc_xfer_to_deadstemc(:)
    real(rk8), pointer, contiguous :: frootc_to_litter(:)
    real(rk8), pointer, contiguous :: frootc_xfer_to_frootc(:)
    real(rk8), pointer, contiguous :: froot_mr(:)
    real(rk8), pointer, contiguous :: grain_mr(:)
    real(rk8), pointer, contiguous :: froot_curmr(:)
    real(rk8), pointer, contiguous :: froot_xsmr(:)
    real(rk8), pointer, contiguous :: gpp(:)  !GPP flux before downregulation (gC/m2/s)
    real(rk8), pointer, contiguous :: gr(:)   ! (gC/m2/s) total growth respiration
    real(rk8), pointer, contiguous :: leafc_to_litter(:)
    real(rk8), pointer, contiguous :: leafc_xfer_to_leafc(:)
    real(rk8), pointer, contiguous :: leaf_mr(:)
    real(rk8), pointer, contiguous :: leaf_curmr(:)
    real(rk8), pointer, contiguous :: leaf_xsmr(:)
    ! (gC/m2/s) litterfall (leaves and fine roots)
    real(rk8), pointer, contiguous :: litfall(:)
    real(rk8), pointer, contiguous :: livecrootc_xfer_to_livecrootc(:)
    real(rk8), pointer, contiguous :: livecroot_mr(:)
    real(rk8), pointer, contiguous :: livecroot_curmr(:)
    real(rk8), pointer, contiguous :: livecroot_xsmr(:)
    real(rk8), pointer, contiguous :: livestemc_xfer_to_livestemc(:)
    real(rk8), pointer, contiguous :: livestem_mr(:)
    real(rk8), pointer, contiguous :: livestem_curmr(:)
    real(rk8), pointer, contiguous :: livestem_xsmr(:)

    ! fire variables changed by F. Li and S. Levis
    real(rk8), pointer, contiguous :: m_leafc_to_fire(:)
    real(rk8), pointer, contiguous :: m_leafc_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_leafc_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_livestemc_to_fire(:)
    real(rk8), pointer, contiguous :: m_livestemc_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_livestemc_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemc_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemc_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemc_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_frootc_to_fire(:)
    real(rk8), pointer, contiguous :: m_frootc_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_frootc_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootc_to_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootc_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootc_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_gresp_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_gresp_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_leafc_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_leafc_storage_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_leafc_xfer_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livestemc_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livestemc_storage_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livestemc_xfer_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livestemc_to_deadstemc_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemc_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemc_storage_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemc_xfer_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_frootc_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_frootc_storage_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_frootc_xfer_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootc_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootc_storage_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootc_xfer_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootc_to_deadcrootc_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_storage_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_xfer_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_gresp_storage_to_litter_fire(:)
    real(rk8), pointer, contiguous :: m_gresp_xfer_to_litter_fire(:)

    real(rk8), pointer, contiguous :: m_deadcrootc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_to_litter(:)
    real(rk8), pointer, contiguous :: m_deadcrootc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: m_deadstemc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: m_deadstemc_to_litter(:)
    real(rk8), pointer, contiguous :: m_deadstemc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: m_frootc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: m_frootc_to_litter(:)
    real(rk8), pointer, contiguous :: m_frootc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: m_gresp_storage_to_litter(:)
    real(rk8), pointer, contiguous :: m_gresp_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: m_leafc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: m_leafc_to_litter(:)
    real(rk8), pointer, contiguous :: m_leafc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: m_livecrootc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: m_livecrootc_to_litter(:)
    real(rk8), pointer, contiguous :: m_livecrootc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: m_livestemc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: m_livestemc_to_litter(:)
    real(rk8), pointer, contiguous :: m_livestemc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_leafc_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_leafc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_leafc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_frootc_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_frootc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_frootc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_livestemc_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_livestemc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_livestemc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_deadstemc_to_prod10c(:)
    real(rk8), pointer, contiguous :: hrv_deadstemc_to_prod100c(:)
    real(rk8), pointer, contiguous :: hrv_deadstemc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_deadstemc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_livecrootc_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_livecrootc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_livecrootc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_deadcrootc_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_deadcrootc_storage_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_deadcrootc_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_gresp_storage_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_gresp_xfer_to_litter(:)
    real(rk8), pointer, contiguous :: hrv_xsmrpool_to_atm(:)
    real(rk8), pointer, contiguous :: col_hrv_xsmrpool_to_atm(:)
    real(rk8), pointer, contiguous :: mr(:)     ! (gC/m2/s) maintenance respiration
    real(rk8), pointer, contiguous :: npp(:)    ! (gC/m2/s) net primary production
    ! (gC/m2/s) total pft-level fire C loss
    real(rk8), pointer, contiguous :: pft_fire_closs(:)
    real(rk8), pointer, contiguous :: psnshade_to_cpool(:)
    real(rk8), pointer, contiguous :: psnsun_to_cpool(:)
    ! (gC/m2/s) root respiration (fine root MR + total root GR)
    real(rk8), pointer, contiguous :: rr(:)
    ! (gC/m2/s) growth resp for growth sent to storage for later display
    real(rk8), pointer, contiguous :: storage_gr(:)
    real(rk8), pointer, contiguous :: transfer_deadcroot_gr(:)
    real(rk8), pointer, contiguous :: transfer_deadstem_gr(:)
    real(rk8), pointer, contiguous :: transfer_froot_gr(:)
    ! (gC/m2/s) growth resp for transfer growth displayed in this timestep
    real(rk8), pointer, contiguous :: transfer_gr(:)
    real(rk8), pointer, contiguous :: transfer_leaf_gr(:)
    real(rk8), pointer, contiguous :: transfer_livecroot_gr(:)
    real(rk8), pointer, contiguous :: transfer_livestem_gr(:)
    ! (gC/m2/s) pft-level wood harvest (to product pools)
    real(rk8), pointer, contiguous :: wood_harvestc(:)
    ! (gC/m2/s) pft-level fire loss (obsolete, mark for removal)
    real(rk8), pointer, contiguous :: vegfire(:)
    ! (gC/m2) temporary photosynthate C pool
    real(rk8), pointer, contiguous :: cpool(:)
    ! (gC/m2) temporary photosynthate C pool
    real(rk8), pointer, contiguous :: xsmrpool(:)
    ! (gC/m2) pft-level sink for C truncation
    real(rk8), pointer, contiguous :: pft_ctrunc(:)
    real(rk8), pointer, contiguous :: deadcrootc(:)         ! (gC/m2) dead coarse root C
    real(rk8), pointer, contiguous :: deadcrootc_storage(:) ! (gC/m2) dead cors root C strg
    real(rk8), pointer, contiguous :: deadcrootc_xfer(:)    ! (gC/m2) dead cors root C trnf
    real(rk8), pointer, contiguous :: deadstemc(:)          ! (gC/m2) dead stem C
    real(rk8), pointer, contiguous :: deadstemc_storage(:)  ! (gC/m2) dead stem C storage
    real(rk8), pointer, contiguous :: deadstemc_xfer(:)     ! (gC/m2) dead stem C transfer
    ! (gC/m2) displayed veg carbon, excluding storage and cpool
    real(rk8), pointer, contiguous :: dispvegc(:)
    real(rk8), pointer, contiguous :: frootc(:)             ! (gC/m2) fine root C
    real(rk8), pointer, contiguous :: frootc_storage(:)     ! (gC/m2) fine root C storage
    real(rk8), pointer, contiguous :: frootc_xfer(:)        ! (gC/m2) fine root C transfer
    real(rk8), pointer, contiguous :: gresp_storage(:)      ! (gC/m2) growth resp strg
    real(rk8), pointer, contiguous :: gresp_xfer(:)         ! (gC/m2) growth resp trnf
    real(rk8), pointer, contiguous :: leafc(:)              ! (gC/m2) leaf C
    real(rk8), pointer, contiguous :: leafc_storage(:)      ! (gC/m2) leaf C storage
    real(rk8), pointer, contiguous :: leafc_xfer(:)         ! (gC/m2) leaf C transfer
    real(rk8), pointer, contiguous :: livecrootc(:)         ! (gC/m2) live coarse root C
    real(rk8), pointer, contiguous :: livecrootc_storage(:) ! (gC/m2) live cors root C strg
    real(rk8), pointer, contiguous :: livecrootc_xfer(:)    ! (gC/m2) live cors root C trnf
    real(rk8), pointer, contiguous :: livestemc(:)          ! (gC/m2) live stem C
    real(rk8), pointer, contiguous :: livestemc_storage(:)  ! (gC/m2) live stem C storage
    real(rk8), pointer, contiguous :: livestemc_xfer(:)     ! (gC/m2) live stem C transfer
    ! (gC/m2) stored vegetation carbon, excluding cpool
    real(rk8), pointer, contiguous :: storvegc(:)
    ! (gC/m2) total pft-level carbon, including cpool
    real(rk8), pointer, contiguous :: totpftc(:)
    ! (gC/m2) total vegetation carbon, excluding cpool
    real(rk8), pointer, contiguous :: totvegc(:)
    ! temporary annual sum of NPP (gC/m2/yr)
    real(rk8), pointer, contiguous :: tempsum_npp(:)
#if (defined CNDV)
    !temporary annual sum of litfall (gC/m2/yr)
    real(rk8), pointer, contiguous :: tempsum_litfall(:)
#endif
    ! for landcover change
    real(rk8), pointer, contiguous :: landuseflux(:) ! (gC/m2/s) dwt_closs+product_closs
    real(rk8), pointer, contiguous :: landuptake(:)  ! (gC/m2/s) nee-landuseflux
    ! (gC/m2/s) total carbon loss from land cover conversion
    real(rk8), pointer, contiguous :: dwt_closs(:)
    ! (gC/m2/s) conversion C flux (immediate loss to atm)
    real(rk8), pointer, contiguous :: dwt_conv_cflux(:)
    ! (gC/m2/s) loss from 10-yr wood product pool
    real(rk8), pointer, contiguous :: prod10c_loss(:)
    ! (gC/m2/s) loss from 100-yr wood product pool
    real(rk8), pointer, contiguous :: prod100c_loss(:)
    ! (gC/m2/s) total wood product carbon loss
    real(rk8), pointer, contiguous :: product_closs(:)
    ! (gC/m2) column-level pool for seeding new PFTs
    real(rk8), pointer, contiguous :: seedc(:)
    ! (gC/m2) wood product C pool, 10-year lifespan
    real(rk8), pointer, contiguous :: prod10c(:)
    ! (gC/m2) wood product C pool, 100-year lifespan
    real(rk8), pointer, contiguous :: prod100c(:)
    real(rk8), pointer, contiguous :: totprodc(:)       ! (gC/m2) total wood product C

    real(rk8), pointer, contiguous :: frootc_alloc(:)   ! fine root C allocation (gC/m2/s)
    real(rk8), pointer, contiguous :: frootc_loss(:)    ! fine root C loss (gC/m2/s)
    real(rk8), pointer, contiguous :: leafc_alloc(:)    ! leaf C allocation (gC/m2/s)
    real(rk8), pointer, contiguous :: leafc_loss(:)     ! leaf C loss (gC/m2/s)
    real(rk8), pointer, contiguous :: woodc(:)          ! wood C (gC/m2)
    real(rk8), pointer, contiguous :: woodc_alloc(:)    ! wood C allocation (gC/m2/s)
    real(rk8), pointer, contiguous :: woodc_loss(:)     ! wood C loss (gC/m2/s)
    ! coarse woody debris C heterotrophic respiration (gC/m2/s)
    real(rk8), pointer, contiguous :: cwdc_hr(:)
    ! coarse woody debris C loss (gC/m2/s)
    real(rk8), pointer, contiguous :: cwdc_loss(:)
    real(rk8), pointer, contiguous :: litterc_loss(:)   ! litter C loss (gC/m2/s)
    real(rk8), pointer, contiguous :: decomp_cascade_ctransfer_vr(:,:,:)
    real(rk8), pointer, contiguous :: decomp_cascade_ctransfer(:,:)
    ! total SOM C loss from vertical transport (gC/m^2/s)
    real(rk8), pointer, contiguous :: som_c_leached(:)
    ! C loss from vertical transport from each decomposing C pool (gC/m^2/s)
    real(rk8), pointer, contiguous :: decomp_cpools_leached(:,:)
    ! C tendency due to vertical transport in decomposing C pools (gC/m^3/s)
    real(rk8), pointer, contiguous :: decomp_cpools_transport_tendency(:,:,:)
    ! temp variables for making lagged npp
    real(rk8) :: nfixlags

    type(pft_cflux_type), pointer :: pcisof
    type(pft_cstate_type), pointer :: pcisos
    type(column_cflux_type), pointer :: ccisof
    type(column_cstate_type), pointer :: ccisos
    integer(ik4) :: c,p,j,k,l        ! indices
    integer(ik4) :: fp,fc        ! lake filter indices
    real(rk8) :: maxdepth    ! depth to integrate soil variables

    ! select which isotope
    select case (isotope)
      case ('bulk')
        pcisof => clm3%g%l%c%p%pcf
        pcisos => clm3%g%l%c%p%pcs
        ccisof => clm3%g%l%c%ccf
        ccisos => clm3%g%l%c%ccs
      case ('c14')
        pcisof => clm3%g%l%c%p%pc14f
        pcisos => clm3%g%l%c%p%pc14s
        ccisof => clm3%g%l%c%cc14f
        ccisos => clm3%g%l%c%cc14s
      case ('c13')
        pcisof => clm3%g%l%c%p%pc13f
        pcisos => clm3%g%l%c%p%pc13s
        ccisof => clm3%g%l%c%cc13f
        ccisos => clm3%g%l%c%cc13s
      case default
        call fatal(__FILE__,__LINE__, &
          'CNCIsoSummaryMod: iso must be bulk, c13 or c14')
    end select

    ! assign local pointers
    ivt                            => clm3%g%l%c%p%itype
    col_fire_closs                 => ccisof%col_fire_closs
    er                             => ccisof%er
    hr                             => ccisof%hr
    litfire                        => ccisof%litfire
    lithr                          => ccisof%lithr
    col_totpftc                    => ccisos%pcs_a%totpftc
    col_totvegc                    => ccisos%pcs_a%totvegc
    cwdc                           => ccisos%cwdc
    col_ctrunc                     => ccisos%col_ctrunc
    decomp_cascade_hr_vr           => ccisof%decomp_cascade_hr_vr
    decomp_cascade_hr              => ccisof%decomp_cascade_hr
    hr_vr                          => ccisof%hr_vr
    m_decomp_cpools_to_fire_vr     => ccisof%m_decomp_cpools_to_fire_vr
    m_decomp_cpools_to_fire        => ccisof%m_decomp_cpools_to_fire
    decomp_cascade_ctransfer_vr    => ccisof%decomp_cascade_ctransfer_vr
    decomp_cascade_ctransfer       => ccisof%decomp_cascade_ctransfer
    decomp_cpools_vr               => ccisos%decomp_cpools_vr
    decomp_cpools                  => ccisos%decomp_cpools
    decomp_cpools_1m               => ccisos%decomp_cpools_1m
    altmax_indx                    => clm3%g%l%c%cps%altmax_indx
    altmax_lastyear_indx           => clm3%g%l%c%cps%altmax_lastyear_indx
    col_ctrunc_vr                  => ccisos%col_ctrunc_vr
    cascade_donor_pool             => decomp_cascade_con%cascade_donor_pool
    is_litter                      => decomp_cascade_con%is_litter
    is_soil                        => decomp_cascade_con%is_soil
    is_cwd                         => decomp_cascade_con%is_cwd
    nee                            => ccisof%nee
    nep                            => ccisof%nep
    nbp                            => ccisof%nbp
    col_ar                         => ccisof%pcf_a%ar
    col_gpp                        => ccisof%pcf_a%gpp
    col_npp                        => ccisof%pcf_a%npp
    col_pft_fire_closs             => ccisof%pcf_a%pft_fire_closs
    col_litfall                    => ccisof%pcf_a%litfall
    col_rr                         => ccisof%pcf_a%rr
    col_vegfire                    => ccisof%pcf_a%vegfire
    col_wood_harvestc              => ccisof%pcf_a%wood_harvestc
    somfire                        => ccisof%somfire
    somhr                          => ccisof%somhr
    sr                             => ccisof%sr
    totfire                        => ccisof%totfire
    cwdc_hr                        => ccisof%cwdc_hr
    cwdc_loss                      => ccisof%cwdc_loss
    litterc_loss                   => ccisof%litterc_loss
    ! dynamic landcover pointers
    dwt_closs                      => ccisof%dwt_closs
    landuseflux                    => ccisof%landuseflux
    landuptake                     => ccisof%landuptake
    dwt_conv_cflux                 => ccisof%dwt_conv_cflux
    seedc                          => ccisos%seedc

    ! wood product pointers
    prod10c_loss                   => ccisof%prod10c_loss
    prod100c_loss                  => ccisof%prod100c_loss
    product_closs                  => ccisof%product_closs
    prod10c                        => ccisos%prod10c
    prod100c                       => ccisos%prod100c
    totprodc                       => ccisos%totprodc

    totcolc                        => ccisos%totcolc
    totecosysc                     => ccisos%totecosysc
    totlitc                        => ccisos%totlitc
    totlitc_1m                     => ccisos%totlitc_1m
    totsomc                        => ccisos%totsomc
    totsomc_1m                     => ccisos%totsomc_1m
    agnpp                          => pcisof%agnpp
    ar                             => pcisof%ar
    bgnpp                          => pcisof%bgnpp
    xsmrpool_to_atm                => pcisof%xsmrpool_to_atm
    cpool_grain_gr                 => pcisof%cpool_grain_gr
    cpool_grain_storage_gr         => pcisof%cpool_grain_storage_gr
    cpool_to_grainc                => pcisof%cpool_to_grainc
    grainc_xfer_to_grainc          => pcisof%grainc_xfer_to_grainc
    transfer_grain_gr              => pcisof%transfer_grain_gr
    grainc_to_food                 => pcisof%grainc_to_food
    livestemc_to_litter            => pcisof%livestemc_to_litter
    grainc                         => pcisos%grainc
    grainc_storage                 => pcisos%grainc_storage
    grainc_xfer                    => pcisos%grainc_xfer
    cpool_deadcroot_gr             => pcisof%cpool_deadcroot_gr
    cpool_deadcroot_storage_gr     => pcisof%cpool_deadcroot_storage_gr
    cpool_deadstem_gr              => pcisof%cpool_deadstem_gr
    cpool_deadstem_storage_gr      => pcisof%cpool_deadstem_storage_gr
    cpool_froot_gr                 => pcisof%cpool_froot_gr
    cpool_froot_storage_gr         => pcisof%cpool_froot_storage_gr
    cpool_leaf_gr                  => pcisof%cpool_leaf_gr
    cpool_leaf_storage_gr          => pcisof%cpool_leaf_storage_gr
    cpool_livecroot_gr             => pcisof%cpool_livecroot_gr
    cpool_livecroot_storage_gr     => pcisof%cpool_livecroot_storage_gr
    cpool_livestem_gr              => pcisof%cpool_livestem_gr
    cpool_livestem_storage_gr      => pcisof%cpool_livestem_storage_gr
    cpool_to_deadcrootc            => pcisof%cpool_to_deadcrootc
    cpool_to_deadstemc             => pcisof%cpool_to_deadstemc
    cpool_to_frootc                => pcisof%cpool_to_frootc
    cpool_to_leafc                 => pcisof%cpool_to_leafc
    cpool_to_livecrootc            => pcisof%cpool_to_livecrootc
    cpool_to_livestemc             => pcisof%cpool_to_livestemc
    current_gr                     => pcisof%current_gr
    deadcrootc_xfer_to_deadcrootc  => pcisof%deadcrootc_xfer_to_deadcrootc
    deadstemc_xfer_to_deadstemc    => pcisof%deadstemc_xfer_to_deadstemc
    frootc_to_litter               => pcisof%frootc_to_litter
    frootc_xfer_to_frootc          => pcisof%frootc_xfer_to_frootc
    froot_mr                       => pcisof%froot_mr
    froot_curmr                    => pcisof%froot_curmr
    froot_xsmr                     => pcisof%froot_xsmr
    grain_mr                       => pcisof%grain_mr
    gpp                            => pcisof%gpp
    gr                             => pcisof%gr
    leafc_to_litter                => pcisof%leafc_to_litter
    leafc_xfer_to_leafc            => pcisof%leafc_xfer_to_leafc
    leaf_mr                        => pcisof%leaf_mr
    leaf_curmr                     => pcisof%leaf_curmr
    leaf_xsmr                      => pcisof%leaf_xsmr
    litfall                        => pcisof%litfall
    livecrootc_xfer_to_livecrootc  => pcisof%livecrootc_xfer_to_livecrootc
    livecroot_mr                   => pcisof%livecroot_mr
    livecroot_curmr                => pcisof%livecroot_curmr
    livecroot_xsmr                 => pcisof%livecroot_xsmr
    livestemc_xfer_to_livestemc    => pcisof%livestemc_xfer_to_livestemc
    livestem_mr                    => pcisof%livestem_mr
    livestem_curmr                 => pcisof%livestem_curmr
    livestem_xsmr                  => pcisof%livestem_xsmr

! fire variables changed by F. Li and S. Levis
    m_leafc_to_fire                => pcisof%m_leafc_to_fire
    m_leafc_storage_to_fire        => pcisof%m_leafc_storage_to_fire
    m_leafc_xfer_to_fire           => pcisof%m_leafc_xfer_to_fire
    m_livestemc_to_fire            => pcisof%m_livestemc_to_fire
    m_livestemc_storage_to_fire    => pcisof%m_livestemc_storage_to_fire
    m_livestemc_xfer_to_fire       => pcisof%m_livestemc_xfer_to_fire
    m_deadstemc_to_fire            => pcisof%m_deadstemc_to_fire
    m_deadstemc_storage_to_fire    => pcisof%m_deadstemc_storage_to_fire
    m_deadstemc_xfer_to_fire       => pcisof%m_deadstemc_xfer_to_fire
    m_frootc_to_fire               => pcisof%m_frootc_to_fire
    m_frootc_storage_to_fire       => pcisof%m_frootc_storage_to_fire
    m_frootc_xfer_to_fire          => pcisof%m_frootc_xfer_to_fire
    m_livecrootc_to_fire           => pcisof%m_livecrootc_to_fire
    m_livecrootc_storage_to_fire   => pcisof%m_livecrootc_storage_to_fire
    m_livecrootc_xfer_to_fire      => pcisof%m_livecrootc_xfer_to_fire
    m_deadcrootc_to_fire           => pcisof%m_deadcrootc_to_fire
    m_deadcrootc_storage_to_fire   => pcisof%m_deadcrootc_storage_to_fire
    m_deadcrootc_xfer_to_fire      => pcisof%m_deadcrootc_xfer_to_fire
    m_gresp_storage_to_fire        => pcisof%m_gresp_storage_to_fire
    m_gresp_xfer_to_fire           => pcisof%m_gresp_xfer_to_fire
    m_leafc_to_litter_fire           => pcisof%m_leafc_to_litter_fire
    m_leafc_storage_to_litter_fire   => pcisof%m_leafc_storage_to_litter_fire
    m_leafc_xfer_to_litter_fire      => pcisof%m_leafc_xfer_to_litter_fire
    m_livestemc_to_litter_fire       => pcisof%m_livestemc_to_litter_fire
    m_livestemc_storage_to_litter_fire => &
            pcisof%m_livestemc_storage_to_litter_fire
    m_livestemc_xfer_to_litter_fire => pcisof%m_livestemc_xfer_to_litter_fire
    m_livestemc_to_deadstemc_fire   => pcisof%m_livestemc_to_deadstemc_fire
    m_deadstemc_to_litter_fire      => pcisof%m_deadstemc_to_litter_fire
    m_deadstemc_storage_to_litter_fire  => &
            pcisof%m_deadstemc_storage_to_litter_fire
    m_deadstemc_xfer_to_litter_fire => pcisof%m_deadstemc_xfer_to_litter_fire
    m_frootc_to_litter_fire         => pcisof%m_frootc_to_litter_fire
    m_frootc_storage_to_litter_fire => pcisof%m_frootc_storage_to_litter_fire
    m_frootc_xfer_to_litter_fire    => pcisof%m_frootc_xfer_to_litter_fire
    m_livecrootc_to_litter_fire     => pcisof%m_livecrootc_to_litter_fire
    m_livecrootc_storage_to_litter_fire => &
            pcisof%m_livecrootc_storage_to_litter_fire
    m_livecrootc_xfer_to_litter_fire    => &
            pcisof%m_livecrootc_xfer_to_litter_fire
    m_livecrootc_to_deadcrootc_fire => pcisof%m_livecrootc_to_deadcrootc_fire
    m_deadcrootc_to_litter_fire         => pcisof%m_deadcrootc_to_litter_fire
    m_deadcrootc_storage_to_litter_fire => &
            pcisof%m_deadcrootc_storage_to_litter_fire
    m_deadcrootc_xfer_to_litter_fire    => &
            pcisof%m_deadcrootc_xfer_to_litter_fire
    m_gresp_storage_to_litter_fire  => pcisof%m_gresp_storage_to_litter_fire
    m_gresp_xfer_to_litter_fire     => pcisof%m_gresp_xfer_to_litter_fire

    m_deadcrootc_storage_to_litter => pcisof%m_deadcrootc_storage_to_litter
    m_deadcrootc_to_litter         => pcisof%m_deadcrootc_to_litter
    m_deadcrootc_xfer_to_litter    => pcisof%m_deadcrootc_xfer_to_litter
    m_deadstemc_storage_to_litter  => pcisof%m_deadstemc_storage_to_litter
    m_deadstemc_to_litter          => pcisof%m_deadstemc_to_litter
    m_deadstemc_xfer_to_litter     => pcisof%m_deadstemc_xfer_to_litter
    m_frootc_storage_to_litter     => pcisof%m_frootc_storage_to_litter
    m_frootc_to_litter             => pcisof%m_frootc_to_litter
    m_frootc_xfer_to_litter        => pcisof%m_frootc_xfer_to_litter
    m_gresp_storage_to_litter      => pcisof%m_gresp_storage_to_litter
    m_gresp_xfer_to_litter         => pcisof%m_gresp_xfer_to_litter
    m_leafc_storage_to_litter      => pcisof%m_leafc_storage_to_litter
    m_leafc_to_litter              => pcisof%m_leafc_to_litter
    m_leafc_xfer_to_litter         => pcisof%m_leafc_xfer_to_litter
    m_livecrootc_storage_to_litter => pcisof%m_livecrootc_storage_to_litter
    m_livecrootc_to_litter         => pcisof%m_livecrootc_to_litter
    m_livecrootc_xfer_to_litter    => pcisof%m_livecrootc_xfer_to_litter
    m_livestemc_storage_to_litter  => pcisof%m_livestemc_storage_to_litter
    m_livestemc_to_litter          => pcisof%m_livestemc_to_litter
    m_livestemc_xfer_to_litter     => pcisof%m_livestemc_xfer_to_litter
    hrv_leafc_to_litter               => pcisof%hrv_leafc_to_litter
    hrv_leafc_storage_to_litter       => pcisof%hrv_leafc_storage_to_litter
    hrv_leafc_xfer_to_litter          => pcisof%hrv_leafc_xfer_to_litter
    hrv_frootc_to_litter              => pcisof%hrv_frootc_to_litter
    hrv_frootc_storage_to_litter      => pcisof%hrv_frootc_storage_to_litter
    hrv_frootc_xfer_to_litter         => pcisof%hrv_frootc_xfer_to_litter
    hrv_livestemc_to_litter           => pcisof%hrv_livestemc_to_litter
    hrv_livestemc_storage_to_litter   => pcisof%hrv_livestemc_storage_to_litter
    hrv_livestemc_xfer_to_litter      => pcisof%hrv_livestemc_xfer_to_litter
    hrv_deadstemc_to_prod10c          => pcisof%hrv_deadstemc_to_prod10c
    hrv_deadstemc_to_prod100c         => pcisof%hrv_deadstemc_to_prod100c
    hrv_deadstemc_storage_to_litter   => pcisof%hrv_deadstemc_storage_to_litter
    hrv_deadstemc_xfer_to_litter      => pcisof%hrv_deadstemc_xfer_to_litter
    hrv_livecrootc_to_litter          => pcisof%hrv_livecrootc_to_litter
    hrv_livecrootc_storage_to_litter  => pcisof%hrv_livecrootc_storage_to_litter
    hrv_livecrootc_xfer_to_litter     => pcisof%hrv_livecrootc_xfer_to_litter
    hrv_deadcrootc_to_litter          => pcisof%hrv_deadcrootc_to_litter
    hrv_deadcrootc_storage_to_litter  => pcisof%hrv_deadcrootc_storage_to_litter
    hrv_deadcrootc_xfer_to_litter     => pcisof%hrv_deadcrootc_xfer_to_litter
    hrv_gresp_storage_to_litter       => pcisof%hrv_gresp_storage_to_litter
    hrv_gresp_xfer_to_litter          => pcisof%hrv_gresp_xfer_to_litter
    hrv_xsmrpool_to_atm               => pcisof%hrv_xsmrpool_to_atm
    col_hrv_xsmrpool_to_atm           => ccisof%pcf_a%hrv_xsmrpool_to_atm
    mr                             => pcisof%mr
    npp                            => pcisof%npp
    pft_fire_closs                 => pcisof%pft_fire_closs
    psnshade_to_cpool              => pcisof%psnshade_to_cpool
    psnsun_to_cpool                => pcisof%psnsun_to_cpool
    rr                             => pcisof%rr
    storage_gr                     => pcisof%storage_gr
    transfer_deadcroot_gr          => pcisof%transfer_deadcroot_gr
    transfer_deadstem_gr           => pcisof%transfer_deadstem_gr
    transfer_froot_gr              => pcisof%transfer_froot_gr
    transfer_gr                    => pcisof%transfer_gr
    transfer_leaf_gr               => pcisof%transfer_leaf_gr
    transfer_livecroot_gr          => pcisof%transfer_livecroot_gr
    transfer_livestem_gr           => pcisof%transfer_livestem_gr
    vegfire                        => pcisof%vegfire
    wood_harvestc                  => pcisof%wood_harvestc
    frootc_alloc                   => pcisof%frootc_alloc
    frootc_loss                    => pcisof%frootc_loss
    leafc_alloc                    => pcisof%leafc_alloc
    leafc_loss                     => pcisof%leafc_loss
    woodc_alloc                    => pcisof%woodc_alloc
    woodc_loss                     => pcisof%woodc_loss
    cpool                          => pcisos%cpool
    xsmrpool                       => pcisos%xsmrpool
    pft_ctrunc                     => pcisos%pft_ctrunc
    deadcrootc                     => pcisos%deadcrootc
    deadcrootc_storage             => pcisos%deadcrootc_storage
    deadcrootc_xfer                => pcisos%deadcrootc_xfer
    deadstemc                      => pcisos%deadstemc
    deadstemc_storage              => pcisos%deadstemc_storage
    deadstemc_xfer                 => pcisos%deadstemc_xfer
    dispvegc                       => pcisos%dispvegc
    frootc                         => pcisos%frootc
    frootc_storage                 => pcisos%frootc_storage
    frootc_xfer                    => pcisos%frootc_xfer
    gresp_storage                  => pcisos%gresp_storage
    gresp_xfer                     => pcisos%gresp_xfer
    leafc                          => pcisos%leafc
    leafc_storage                  => pcisos%leafc_storage
    leafc_xfer                     => pcisos%leafc_xfer
    livecrootc                     => pcisos%livecrootc
    livecrootc_storage             => pcisos%livecrootc_storage
    livecrootc_xfer                => pcisos%livecrootc_xfer
    livestemc                      => pcisos%livestemc
    livestemc_storage              => pcisos%livestemc_storage
    livestemc_xfer                 => pcisos%livestemc_xfer
    storvegc                       => pcisos%storvegc
    totpftc                        => pcisos%totpftc
    totvegc                        => pcisos%totvegc
    woodc                          => pcisos%woodc
    tempsum_npp                    => clm3%g%l%c%p%pepv%tempsum_npp
#if (defined CNDV)
    tempsum_litfall                => clm3%g%l%c%p%pepv%tempsum_litfall
#endif
    som_c_leached                    => ccisof%som_c_leached
    decomp_cpools_leached            => ccisof%decomp_cpools_leached
    decomp_cpools_transport_tendency => ccisof%decomp_cpools_transport_tendency

    ! pft loop
    do fp = 1, num_soilp
      p = filter_soilp(fp)

      ! calculate pft-level summary carbon fluxes and states

      ! gross primary production (GPP)
      gpp(p) = psnsun_to_cpool(p) + psnshade_to_cpool(p)

      ! maintenance respiration (MR)
      if ( isotope == 'c13' .or. isotope == 'c14') then
        leaf_mr(p)      = leaf_curmr(p)      + leaf_xsmr(p)
        froot_mr(p)     = froot_curmr(p)     + froot_xsmr(p)
        livestem_mr(p)  = livestem_curmr(p)  + livestem_xsmr(p)
        livecroot_mr(p) = livecroot_curmr(p) + livecroot_xsmr(p)
      end if

      mr(p) = leaf_mr(p) + froot_mr(p) + livestem_mr(p) + livecroot_mr(p)

      ! growth respiration (GR)
      ! current GR is respired this time step for new growth displayed in
      ! this timestep
      current_gr(p) = cpool_leaf_gr(p)      + cpool_froot_gr(p)     + &
                      cpool_livestem_gr(p)  + cpool_deadstem_gr(p)  + &
                      cpool_livecroot_gr(p) + cpool_deadcroot_gr(p)

      ! transfer GR is respired this time step for transfer growth
      ! displayed in this timestep
      transfer_gr(p) = &
         transfer_leaf_gr(p)      + &
         transfer_froot_gr(p)     + &
         transfer_livestem_gr(p)  + &
         transfer_deadstem_gr(p)  + &
         transfer_livecroot_gr(p) + &
         transfer_deadcroot_gr(p)

      ! storage GR is respired this time step for growth sent to storage
      ! for later display
      storage_gr(p) = &
         cpool_leaf_storage_gr(p)      + &
         cpool_froot_storage_gr(p)     + &
         cpool_livestem_storage_gr(p)  + &
         cpool_deadstem_storage_gr(p)  + &
         cpool_livecroot_storage_gr(p) + &
         cpool_deadcroot_storage_gr(p)

      if ( crop_prog .and. ivt(p) >= npcropmin ) then
        mr(p) = mr(p) + grain_mr(p)
        current_gr(p) = current_gr(p) + cpool_grain_gr(p)
        transfer_gr(p) = transfer_gr(p) + transfer_grain_gr(p)
        storage_gr(p) = storage_gr(p) + cpool_grain_storage_gr(p)
      end if

      ! GR is the sum of current + transfer + storage GR
      gr(p) = current_gr(p) + transfer_gr(p) + storage_gr(p)

      ! autotrophic respiration (AR)
      if ( crop_prog .and. ivt(p) >= npcropmin ) then
        ar(p) = mr(p) + gr(p) + xsmrpool_to_atm(p) ! xsmr... is -ve (slevis)
      else
        ar(p) = mr(p) + gr(p)
      end if

      ! root respiration (RR)
      rr(p) = &
         froot_mr(p) + &
         cpool_froot_gr(p) + &
         cpool_livecroot_gr(p) + &
         cpool_deadcroot_gr(p) + &
         transfer_froot_gr(p) + &
         transfer_livecroot_gr(p) + &
         transfer_deadcroot_gr(p) + &
         cpool_froot_storage_gr(p) + &
         cpool_livecroot_storage_gr(p) + &
         cpool_deadcroot_storage_gr(p)

      ! net primary production (NPP)
      npp(p) = gpp(p) - ar(p)

      ! update the annual NPP accumulator, for use in allocation code
      if ( isotope == 'bulk' ) then
        tempsum_npp(p) = tempsum_npp(p) + npp(p)
      else
        tempsum_npp(p) = 0.0_rk8
      end if

      if ( is_nan(tempsum_npp(p)) ) then
        write(stderr,*) 'Error in CN Summary: tempsum_npp =', &
                tempsum_npp(p), ' at pft ',p
        write(0,*) 'npp(p) =', npp(p)
        write(0,*) 'gpp(p) =', gpp(p)
        write(0,*) 'ar(p) =', ar(p)
        write(0,*) 'mr(p) =', mr(p)
        write(0,*) 'gr(p) =', gr(p)
        write(0,*) 'leaf_mr(p) =', leaf_mr(p)
        write(0,*) 'froot_mr(p) =', froot_mr(p)
        write(0,*) 'livestem_mr(p) =', livestem_mr(p)
        write(0,*) 'livecroot_mr(p) =', livecroot_mr(p)
        write(0,*) 'tempsum_npp(p) =', tempsum_npp(p)
        call fatal(__FILE__,__LINE__,'clm now stopping')
      end if

      ! aboveground NPP: leaf, live stem, dead stem (AGNPP)
      ! This is supposed to correspond as closely as possible to
      ! field measurements of AGNPP, so it ignores the storage pools
      ! and only treats the fluxes into displayed pools.
      agnpp(p) = &
         cpool_to_leafc(p)                  + &
         leafc_xfer_to_leafc(p)             + &
         cpool_to_livestemc(p)              + &
         livestemc_xfer_to_livestemc(p)     + &
         cpool_to_deadstemc(p)              + &
         deadstemc_xfer_to_deadstemc(p)

     ! belowground NPP: fine root, live coarse root, dead coarse root (BGNPP)
      ! This is supposed to correspond as closely as possible to
      ! field measurements of BGNPP, so it ignores the storage pools
      ! and only treats the fluxes into displayed pools.
      bgnpp(p) = &
         cpool_to_frootc(p)                   + &
         frootc_xfer_to_frootc(p)             + &
         cpool_to_livecrootc(p)               + &
         livecrootc_xfer_to_livecrootc(p)     + &
         cpool_to_deadcrootc(p)               + &
         deadcrootc_xfer_to_deadcrootc(p)

      ! litterfall (LITFALL)
      litfall(p) = &
         leafc_to_litter(p)                 + &
         frootc_to_litter(p)                + &
         m_leafc_to_litter(p)               + &
         m_leafc_storage_to_litter(p)       + &
         m_leafc_xfer_to_litter(p)          + &
         m_frootc_to_litter(p)              + &
         m_frootc_storage_to_litter(p)      + &
         m_frootc_xfer_to_litter(p)         + &
         m_livestemc_to_litter(p)           + &
         m_livestemc_storage_to_litter(p)   + &
         m_livestemc_xfer_to_litter(p)      + &
         m_deadstemc_to_litter(p)           + &
         m_deadstemc_storage_to_litter(p)   + &
         m_deadstemc_xfer_to_litter(p)      + &
         m_livecrootc_to_litter(p)          + &
         m_livecrootc_storage_to_litter(p)  + &
         m_livecrootc_xfer_to_litter(p)     + &
         m_deadcrootc_to_litter(p)          + &
         m_deadcrootc_storage_to_litter(p)  + &
         m_deadcrootc_xfer_to_litter(p)     + &
         m_gresp_storage_to_litter(p)       + &
         m_gresp_xfer_to_litter(p)          + & ! F. Li and S. Levis
         m_leafc_to_litter_fire(p)              + &
         m_leafc_storage_to_litter_fire(p)      + &
         m_leafc_xfer_to_litter_fire(p)         + &
         m_livestemc_to_litter_fire(p)          + &
         m_livestemc_storage_to_litter_fire(p)  + &
         m_livestemc_xfer_to_litter_fire(p)     + &
         m_deadstemc_to_litter_fire(p)          + &
         m_deadstemc_storage_to_litter_fire(p)  + &
         m_deadstemc_xfer_to_litter_fire(p)     + &
         m_frootc_to_litter_fire(p)             + &
         m_frootc_storage_to_litter_fire(p)     + &
         m_frootc_xfer_to_litter_fire(p)        + &
         m_livecrootc_to_litter_fire(p)         + &
         m_livecrootc_storage_to_litter_fire(p) + &
         m_livecrootc_xfer_to_litter_fire(p)    + &
         m_deadcrootc_to_litter_fire(p)         + &
         m_deadcrootc_storage_to_litter_fire(p) + &
         m_deadcrootc_xfer_to_litter_fire(p)    + &
         m_gresp_storage_to_litter_fire(p)      + &
         m_gresp_xfer_to_litter_fire(p)         + &
         hrv_leafc_to_litter(p)             + &
         hrv_leafc_storage_to_litter(p)     + &
         hrv_leafc_xfer_to_litter(p)        + &
         hrv_frootc_to_litter(p)            + &
         hrv_frootc_storage_to_litter(p)    + &
         hrv_frootc_xfer_to_litter(p)       + &
         hrv_livestemc_to_litter(p)         + &
         hrv_livestemc_storage_to_litter(p) + &
         hrv_livestemc_xfer_to_litter(p)    + &
         hrv_deadstemc_storage_to_litter(p) + &
         hrv_deadstemc_xfer_to_litter(p)    + &
         hrv_livecrootc_to_litter(p)        + &
         hrv_livecrootc_storage_to_litter(p)+ &
         hrv_livecrootc_xfer_to_litter(p)   + &
         hrv_deadcrootc_to_litter(p)        + &
         hrv_deadcrootc_storage_to_litter(p)+ &
         hrv_deadcrootc_xfer_to_litter(p)   + &
         hrv_gresp_storage_to_litter(p)     + &
         hrv_gresp_xfer_to_litter(p)

#if (defined CNDV)
      ! update the annual litfall accumulator, for use in mortality code
      tempsum_litfall(p) = tempsum_litfall(p) + &
                           leafc_to_litter(p) + &
                           frootc_to_litter(p)
#endif

      ! pft-level fire losses (VEGFIRE)
      vegfire(p) = 0._rk8

      ! pft-level wood harvest
      wood_harvestc(p) = &
         hrv_deadstemc_to_prod10c(p) + &
         hrv_deadstemc_to_prod100c(p)

      ! pft-level carbon losses to fire changed by F. Li and S. Levis
      pft_fire_closs(p) = &
         m_leafc_to_fire(p)                + &
         m_leafc_storage_to_fire(p)        + &
         m_leafc_xfer_to_fire(p)           + &
         m_frootc_to_fire(p)               + &
         m_frootc_storage_to_fire(p)       + &
         m_frootc_xfer_to_fire(p)          + &
         m_livestemc_to_fire(p)            + &
         m_livestemc_storage_to_fire(p)    + &
         m_livestemc_xfer_to_fire(p)       + &
         m_deadstemc_to_fire(p)            + &
         m_deadstemc_storage_to_fire(p)    + &
         m_deadstemc_xfer_to_fire(p)       + &
         m_livecrootc_to_fire(p)           + &
         m_livecrootc_storage_to_fire(p)   + &
         m_livecrootc_xfer_to_fire(p)      + &
         m_deadcrootc_to_fire(p)           + &
         m_deadcrootc_storage_to_fire(p)   + &
         m_deadcrootc_xfer_to_fire(p)      + &
         m_gresp_storage_to_fire(p)        + &
         m_gresp_xfer_to_fire(p)

      ! displayed vegetation carbon, excluding storage and cpool (DISPVEGC)
      dispvegc(p) = &
         leafc(p)      + &
         frootc(p)     + &
         livestemc(p)  + &
         deadstemc(p)  + &
         livecrootc(p) + &
         deadcrootc(p)

      ! stored vegetation carbon, excluding cpool (STORVEGC)
      storvegc(p) = &
         cpool(p)              + &
         leafc_storage(p)      + &
         frootc_storage(p)     + &
         livestemc_storage(p)  + &
         deadstemc_storage(p)  + &
         livecrootc_storage(p) + &
         deadcrootc_storage(p) + &
         leafc_xfer(p)         + &
         frootc_xfer(p)        + &
         livestemc_xfer(p)     + &
         deadstemc_xfer(p)     + &
         livecrootc_xfer(p)    + &
         deadcrootc_xfer(p)    + &
         gresp_storage(p)      + &
         gresp_xfer(p)

      if ( crop_prog .and. ivt(p) >= npcropmin ) then
        storvegc(p) = storvegc(p) + grainc_storage(p) + grainc_xfer(p)
        agnpp(p) = agnpp(p) + cpool_to_grainc(p) + grainc_xfer_to_grainc(p)
        litfall(p) = litfall(p) + livestemc_to_litter(p) + grainc_to_food(p)
        dispvegc(p) = dispvegc(p) + grainc(p)
      end if

      ! total vegetation carbon, excluding cpool (TOTVEGC)
      totvegc(p) = dispvegc(p) + storvegc(p)

      ! total pft-level carbon, including xsmrpool, ctrunc
      totpftc(p) = totvegc(p) + xsmrpool(p) + pft_ctrunc(p)

      ! new summary variables for CLAMP

      ! (FROOTC_ALLOC) - fine root C allocation
      frootc_alloc(p) = frootc_xfer_to_frootc(p) + cpool_to_frootc(p)

      ! (FROOTC_LOSS) - fine root C loss changed by F. Li and S. Levis
      frootc_loss(p) = &
        m_frootc_to_litter(p)       + &
        m_frootc_to_fire(p)         + &
        m_frootc_to_litter_fire(p)  + &
        hrv_frootc_to_litter(p)     + &
        frootc_to_litter(p)

      ! (LEAFC_ALLOC) - leaf C allocation
      leafc_alloc(p) = leafc_xfer_to_leafc(p) + cpool_to_leafc(p)

      ! (LEAFC_LOSS) - leaf C loss changed by F. Li and S. Levis
      leafc_loss(p) = &
        m_leafc_to_litter(p)      + &
        m_leafc_to_fire(p)        + &
        m_leafc_to_litter_fire(p) + &
        hrv_leafc_to_litter(p)    + &
        leafc_to_litter(p)

      ! (WOODC) - wood C
      woodc(p) = &
        deadstemc(p)    + &
        livestemc(p)    + &
        deadcrootc(p)   + &
        livecrootc(p)

      ! (WOODC_ALLOC) - wood C allocation
      woodc_alloc(p) = &
        livestemc_xfer_to_livestemc(p)  + &
        deadstemc_xfer_to_deadstemc(p)  + &
        livecrootc_xfer_to_livecrootc(p)    + &
        deadcrootc_xfer_to_deadcrootc(p)    + &
        cpool_to_livestemc(p)   + &
        cpool_to_deadstemc(p)   + &
        cpool_to_livecrootc(p)  + &
        cpool_to_deadcrootc(p)

      ! (WOODC_LOSS) - wood C loss
      woodc_loss(p) = &
        m_livestemc_to_litter(p)    + &
        m_deadstemc_to_litter(p)    + &
        m_livecrootc_to_litter(p)   + &
        m_deadcrootc_to_litter(p)   + &
        m_livestemc_to_fire(p)      + &
        m_deadstemc_to_fire(p)      + &
        m_livecrootc_to_fire(p)     + &
        m_deadcrootc_to_fire(p)     + &
        hrv_livestemc_to_litter(p)  + &
        hrv_livestemc_storage_to_litter(p) + &
        hrv_livestemc_xfer_to_litter(p)    + &
        hrv_deadstemc_to_prod10c(p)        + &
        hrv_deadstemc_to_prod100c(p)       + &
        hrv_deadstemc_storage_to_litter(p) + &
        hrv_deadstemc_xfer_to_litter(p)    + &
        hrv_livecrootc_to_litter(p)        + &
        hrv_livecrootc_storage_to_litter(p)+ &
        hrv_livecrootc_xfer_to_litter(p)   + &
        hrv_deadcrootc_to_litter(p)        + &
        hrv_deadcrootc_storage_to_litter(p)+ &
        hrv_deadcrootc_xfer_to_litter(p)

    end do  ! end of pfts loop

    ! use p2c routine to get selected column-average pft-level fluxes and states
    call p2c(num_soilc,filter_soilc,gpp,col_gpp)
    call p2c(num_soilc,filter_soilc,ar,col_ar)
    call p2c(num_soilc,filter_soilc,rr,col_rr)
    call p2c(num_soilc,filter_soilc,npp,col_npp)
    call p2c(num_soilc,filter_soilc,vegfire,col_vegfire)
    call p2c(num_soilc,filter_soilc,wood_harvestc,col_wood_harvestc)
    call p2c(num_soilc,filter_soilc,totvegc,col_totvegc)
    call p2c(num_soilc,filter_soilc,totpftc,col_totpftc)
    call p2c(num_soilc,filter_soilc,pft_fire_closs,col_pft_fire_closs)
    call p2c(num_soilc,filter_soilc,litfall,col_litfall)
    call p2c(num_soilc,filter_soilc,hrv_xsmrpool_to_atm,col_hrv_xsmrpool_to_atm)

    if ( isotope == 'bulk') then
      if (nfix_timeconst > 0._rk8 .and. nfix_timeconst < 500._rk8 ) then
        ! this code is to calculate an exponentially-relaxed npp value
        ! for use in NDynamics code
        col_lag_npp => clm3%g%l%c%cps%col_lag_npp
        nfixlags = nfix_timeconst * secspday
        ! column loop
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          if ( col_lag_npp(c) /= spval ) then
            col_lag_npp(c) = col_lag_npp(c) * exp(-dtsrf/nfixlags) &
                           + col_npp(c) * (1._rk8 - exp(-dtsrf/nfixlags))
          else
            ! first timestep
            col_lag_npp(c) = col_npp(c)
          end if
        end do
      endif
    endif

    ! column loop
    do fc = 1, num_soilc
      c = filter_soilc(fc)

      ! some zeroing
      lithr(c) = 0._rk8
      somhr(c) = 0._rk8
      totlitc(c) = 0._rk8
      totsomc(c) = 0._rk8
      cwdc(c) = 0._rk8
      col_ctrunc(c) = 0._rk8
      cwdc_loss(c) = 0._rk8
      som_c_leached(c) = 0._rk8
      do l = 1, ndecomp_pools
        decomp_cpools(c,l) = 0._rk8
      end do
      totlitc_1m(c) = 0._rk8
      totsomc_1m(c) = 0._rk8
    end do

    ! vertically integrate HR and decomposition cascade fluxes
    do k = 1, ndecomp_cascade_transitions
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_cascade_hr(c,k) = decomp_cascade_hr(c,k) + &
                  decomp_cascade_hr_vr(c,j,k)*dzsoi_decomp(j)
          decomp_cascade_ctransfer(c,k) = decomp_cascade_ctransfer(c,k) + &
                  decomp_cascade_ctransfer_vr(c,j,k) * dzsoi_decomp(j)
        end do
      end do
    end do

    ! litter heterotrophic respiration (LITHR)
    do k = 1, ndecomp_cascade_transitions
      if ( is_litter(cascade_donor_pool(k)) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          lithr(c) = lithr(c) + decomp_cascade_hr(c,k)
        end do
      end if
    end do

    ! soil organic matter heterotrophic respiration (SOMHR)
    do k = 1, ndecomp_cascade_transitions
      if ( is_soil(cascade_donor_pool(k)) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          somhr(c) = somhr(c) + decomp_cascade_hr(c,k)
        end do
      end if
    end do

    ! total heterotrophic respiration (HR)
    do fc = 1, num_soilc
      c = filter_soilc(fc)
      hr(c) = lithr(c) + somhr(c)
    end do

    ! total heterotrophic respiration, vertically resolved (HR)
    do j = 1, nlevdecomp
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        hr_vr(c,j) = 0._rk8
      end do
    end do
    do k = 1, ndecomp_cascade_transitions
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          hr_vr(c,j) = hr_vr(c,j) + decomp_cascade_hr_vr(c,j,k)
        end do
      end do
    end do

    do fc = 1, num_soilc
      c = filter_soilc(fc)
      ! total soil respiration, heterotrophic + root respiration (SR)
      sr(c) = col_rr(c) + hr(c)

      ! total ecosystem respiration, autotrophic + heterotrophic (ER)
      er(c) = col_ar(c) + hr(c)

      ! litter fire losses (LITFIRE)
      litfire(c) = 0._rk8

      ! total wood product loss
      product_closs(c) = &
         prod10c_loss(c) + &
         prod100c_loss(c)

      ! soil organic matter fire losses (SOMFIRE)
      somfire(c) = 0._rk8

      ! total ecosystem fire losses (TOTFIRE)
      totfire(c) = &
         litfire(c) + &
         somfire(c) + &
         col_vegfire(c)
    end do

    ! vertically integrate column-level carbon fire losses
    do l = 1, ndecomp_pools
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          m_decomp_cpools_to_fire(c,l) = m_decomp_cpools_to_fire(c,l) + &
                 m_decomp_cpools_to_fire_vr(c,j,l)*dzsoi_decomp(j)
        end do
      end do
    end do

    ! column-level carbon losses to fire, including pft losses
    do fc = 1, num_soilc
      c = filter_soilc(fc)
      col_fire_closs(c) = col_pft_fire_closs(c)
      do l = 1, ndecomp_pools
        col_fire_closs(c) = col_fire_closs(c) + m_decomp_cpools_to_fire(c,l)
      end do

      ! column-level carbon losses due to landcover change
      dwt_closs(c) = dwt_conv_cflux(c)

      ! net ecosystem production, excludes fire flux, landcover change,
      ! and loss from wood products, positive for sink (NEP)
      nep(c) = col_gpp(c) - er(c)

      ! net biome production of carbon, includes depletion from: fire flux,
      ! landcover change flux, and loss from wood products pools, positive
      ! for sink (NBP)
      nbp(c) = nep(c) - col_fire_closs(c) - dwt_closs(c) - product_closs(c)

      ! net ecosystem exchange of carbon, includes fire flux, landcover
      ! change flux, loss from wood products pools, and hrv_xsmrpool flux,
      ! positive for source (NEE)
      nee(c) = -nep(c) + col_fire_closs(c) + dwt_closs(c) + &
              product_closs(c) + col_hrv_xsmrpool_to_atm(c)
      ! land use flux and land uptake
      landuseflux(c) = dwt_closs(c) + product_closs(c)
      landuptake(c) = nee(c) - landuseflux(c)
    end do

    ! vertically integrate each of the decomposing C pools
    do l = 1, ndecomp_pools
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_cpools(c,l) = decomp_cpools(c,l) + &
                 decomp_cpools_vr(c,j,l) * dzsoi_decomp(j)
        end do
      end do
    end do

    ! for vertically-resolved soil biogeochemistry, calculate some
    ! diagnostics of carbon pools to a given depth
    if ( nlevdecomp > 1) then

      ! zero some pools
      do l = 1, ndecomp_pools
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_cpools_1m(c,l) = 0._rk8
        end do
      end do

      ! vertically integrate each of the decomposing C pools to 1 meter
      maxdepth = 1._rk8
      do l = 1, ndecomp_pools
        do j = 1, nlevdecomp
          if ( zisoi(j) <= maxdepth ) then
            do fc = 1, num_soilc
              c = filter_soilc(fc)
              decomp_cpools_1m(c,l) = decomp_cpools_1m(c,l) + &
                      decomp_cpools_vr(c,j,l) * dzsoi_decomp(j)
            end do
          else if ( zisoi(j-1) < maxdepth ) then
            do fc = 1, num_soilc
              c = filter_soilc(fc)
              decomp_cpools_1m(c,l) = decomp_cpools_1m(c,l) + &
                       decomp_cpools_vr(c,j,l) * (maxdepth - zisoi(j-1))
            end do
          end if
        end do
      end do

      ! total litter carbon in the top meter (TOTLITC_1m)
      do l = 1, ndecomp_pools
        if ( is_litter(l) ) then
          do fc = 1, num_soilc
            c = filter_soilc(fc)
            totlitc_1m(c) = totlitc_1m(c) + decomp_cpools_1m(c,l)
          end do
        end if
      end do

      ! total soil organic matter carbon in the top meter (TOTSOMC_1m)
      do l = 1, ndecomp_pools
        if ( is_soil(l) ) then
          do fc = 1, num_soilc
            c = filter_soilc(fc)
            totsomc_1m(c) = totsomc_1m(c) + decomp_cpools_1m(c,l)
          end do
        end if
      end do
    endif

    ! total litter carbon (TOTLITC)
    do l = 1, ndecomp_pools
      if ( is_litter(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          totlitc(c) = totlitc(c) + decomp_cpools(c,l)
        end do
      end if
    end do

    ! total soil organic matter carbon (TOTSOMC)
    do l = 1, ndecomp_pools
      if ( is_soil(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          totsomc(c) = totsomc(c) + decomp_cpools(c,l)
        end do
      end if
    end do

    ! coarse woody debris carbon
    do l = 1, ndecomp_pools
      if ( is_cwd(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          cwdc(c) = cwdc(c) + decomp_cpools(c,l)
        end do
      end if
    end do

    ! truncation carbon
    do j = 1, nlevdecomp
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        col_ctrunc(c) = col_ctrunc(c) + col_ctrunc_vr(c,j) * dzsoi_decomp(j)
      end do
    end do

    do fc = 1, num_soilc
      c = filter_soilc(fc)
      ! total wood product carbon
      totprodc(c) = prod10c(c) + prod100c(c)

      ! total ecosystem carbon, including veg but excluding cpool (TOTECOSYSC)
      totecosysc(c) = &
           cwdc(c) + &
           totlitc(c) + &
           totsomc(c) + &
           totprodc(c) + &
           col_totvegc(c)

      ! total column carbon, including veg and cpool (TOTCOLC)
      ! adding col_ctrunc, seedc
      totcolc(c) = &
         col_totpftc(c) + &
         cwdc(c) + &
         totlitc(c) + &
         totsomc(c) + &
         totprodc(c) + &
         seedc(c) + &
         col_ctrunc(c)

      ! new summary variables for CLAMP

      ! (CWDC_HR) - coarse woody debris heterotrophic respiration
      cwdc_hr(c) = 0._rk8
    end do

    ! (CWDC_LOSS) - coarse woody debris C loss
    do l = 1, ndecomp_pools
      if ( is_cwd(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          cwdc_loss(c) = cwdc_loss(c) + m_decomp_cpools_to_fire(c,l)
        end do
      end if
    end do

    do k = 1, ndecomp_cascade_transitions
      if ( is_cwd(cascade_donor_pool(k)) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          cwdc_loss(c) = cwdc_loss(c) + decomp_cascade_ctransfer(c,k)
        end do
      end if
    end do

    ! (LITTERC_LOSS) - litter C loss
    do fc = 1, num_soilc
      c = filter_soilc(fc)
      litterc_loss(c) = lithr(c)
    end do
    do l = 1, ndecomp_pools
      if ( is_litter(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          litterc_loss(c) = litterc_loss(c) + m_decomp_cpools_to_fire(c,l)
        end do
      end if
    end do
    do k = 1, ndecomp_cascade_transitions
      if ( is_litter(cascade_donor_pool(k)) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          litterc_loss(c) = litterc_loss(c) + decomp_cascade_ctransfer(c,k)
        end do
      end if
    end do

    ! add up all vertical transport tendency terms and calculate total
    ! som leaching loss as the sum of these
    do l = 1, ndecomp_pools
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        decomp_cpools_leached(c,l) = 0._rk8
      end do
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_cpools_leached(c,l) = decomp_cpools_leached(c,l) + &
                  decomp_cpools_transport_tendency(c,j,l) * dzsoi_decomp(j)
        end do
      end do
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        som_c_leached(c) = som_c_leached(c) + decomp_cpools_leached(c,l)
      end do
    end do
  end subroutine CSummary
  !
  ! On the radiation time step, perform pft and column-level nitrogen
  ! summary calculations
  !
  subroutine NSummary(num_soilc, filter_soilc, num_soilp, filter_soilp)
    use mod_clm_type
    use mod_clm_subgridave, only : p2c
    use mod_clm_varpar, only : nlevdecomp, ndecomp_cascade_transitions, &
            ndecomp_pools
    implicit none
    integer(ik4), intent(in) :: num_soilc ! number of soil columns in filter
    integer(ik4), intent(in) :: filter_soilc(:) ! filter for soil columns
    integer(ik4), intent(in) :: num_soilp       ! number of soil pfts in filter
    integer(ik4), intent(in) :: filter_soilp(:) ! filter for soil pfts

    integer(ik4), pointer, contiguous :: ivt(:)  ! pft vegetation type
    ! (gN/m2/s) total column-level fire N loss
    real(rk8), pointer, contiguous :: col_fire_nloss(:)
    real(rk8), pointer, contiguous :: col_wood_harvestn(:)
    real(rk8), pointer, contiguous :: denit(:)
    ! (gN/m2/s) total pft-level fire C loss
    real(rk8), pointer, contiguous :: col_pft_fire_nloss(:)
    real(rk8), pointer, contiguous :: col_totpftn(:) ! (gN/m2) total pft-level nitrogen
    real(rk8), pointer, contiguous :: col_totvegn(:) ! (gN/m2) total vegetation nitrogen
    real(rk8), pointer, contiguous :: cwdn(:)        ! (gN/m2) coarse woody debris N
    real(rk8), pointer, contiguous :: col_ntrunc(:)  ! (gN/m2) column-level sink for N trunc
    real(rk8), pointer, contiguous :: sminn(:)       ! (gN/m2) soil mineral N
    real(rk8), pointer, contiguous :: m_decomp_npools_to_fire_vr(:,:,:)
    real(rk8), pointer, contiguous :: m_decomp_npools_to_fire(:,:)
    logical, pointer, contiguous :: is_litter(:) ! TRUE => pool is a litter pool
    logical, pointer, contiguous :: is_soil(:)   ! TRUE => pool is a soil pool
    logical, pointer, contiguous :: is_cwd(:)    ! TRUE => pool is a cwd pool
#ifndef NITRIF_DENITRIF
    real(rk8), pointer, contiguous :: sminn_to_denit_excess_vr(:,:)
    real(rk8), pointer, contiguous :: sminn_to_denit_excess(:)
    real(rk8), pointer, contiguous :: sminn_leached_vr(:,:)
    real(rk8), pointer, contiguous :: sminn_leached(:)
    ! vertically-resolved denitrification along decomp cascade (gN/m3/s)
    real(rk8), pointer, contiguous :: sminn_to_denit_decomp_cascade_vr(:,:,:)
    ! vertically-integrated denitrification along decomp cascade (gN/m2/s)
    real(rk8), pointer, contiguous :: sminn_to_denit_decomp_cascade(:,:)
#else
    real(rk8), pointer, contiguous :: smin_no3(:)
    real(rk8), pointer, contiguous :: smin_nh4(:)
    real(rk8), pointer, contiguous :: smin_no3_vr(:,:)
    real(rk8), pointer, contiguous :: smin_nh4_vr(:,:)
    real(rk8), pointer, contiguous :: f_nit_vr(:,:)
    real(rk8), pointer, contiguous :: f_nit(:)
    real(rk8), pointer, contiguous :: f_denit_vr(:,:)
    real(rk8), pointer, contiguous :: f_denit(:)
    real(rk8), pointer, contiguous :: pot_f_nit_vr(:,:)
    real(rk8), pointer, contiguous :: pot_f_nit(:)
    real(rk8), pointer, contiguous :: pot_f_denit_vr(:,:)
    real(rk8), pointer, contiguous :: pot_f_denit(:)
    ! flux of N2o from denitrification [gN/m3/s]
    real(rk8), pointer, contiguous :: f_n2o_denit_vr(:,:)
    ! flux of N2o from denitrification [gN/m2/s]
    real(rk8), pointer, contiguous :: f_n2o_denit(:)
    ! flux of N2o from nitrification [gN/m3/s]
    real(rk8), pointer, contiguous :: f_n2o_nit_vr(:,:)
    ! flux of N2o from nitrification [gN/m2/s]
    real(rk8), pointer, contiguous :: f_n2o_nit(:)
    ! samy : Total N2O flux from soil to atmosphere
    real(rk8), pointer, contiguous :: f_n2o_tot(:)
    real(rk8), pointer, contiguous :: f_n2o_tot_vr(:,:)
    real(rk8), pointer, contiguous :: smin_no3_leached_vr(:,:)
    real(rk8), pointer, contiguous :: smin_no3_leached(:)
    real(rk8), pointer, contiguous :: smin_no3_runoff_vr(:,:)
    real(rk8), pointer, contiguous :: smin_no3_runoff(:)
#endif
    ! (gN/m2)  decomposing (litter, cwd, soil) N pools
    real(rk8), pointer, contiguous :: decomp_npools(:,:)
    ! (gN/m3)  vertically-resolved decomposing (litter, cwd, soil) N pools
    real(rk8), pointer, contiguous :: decomp_npools_vr(:,:,:)
    ! (gN/m2)  diagnostic: decomposing (litter, cwd, soil) N pools to 1 meter
    real(rk8), pointer, contiguous :: decomp_npools_1m(:,:)
    ! maximum annual depth of thaw
    integer(ik4), pointer, contiguous :: altmax_indx(:)
    ! prior year maximum annual depth of thaw
    integer(ik4), pointer, contiguous :: altmax_lastyear_indx(:)
    ! (gN/m3) soil mineral N
    real(rk8), pointer, contiguous :: sminn_vr(:,:)
    ! (gN/m3) column-level sink for N truncation
    real(rk8), pointer, contiguous :: col_ntrunc_vr(:,:)
    real(rk8), pointer, contiguous :: supplement_to_sminn(:)
    real(rk8), pointer, contiguous :: supplement_to_sminn_vr(:,:)
    real(rk8), pointer, contiguous :: totcoln(:)    ! (gN/m2) total column N, incl veg
    real(rk8), pointer, contiguous :: totecosysn(:) ! (gN/m2) total ecosys N, incl veg
    real(rk8), pointer, contiguous :: totlitn(:)    ! (gN/m2) total litter N
    real(rk8), pointer, contiguous :: totlitn_1m(:) ! (gN/m2) total litter N to 1 meter
    real(rk8), pointer, contiguous :: totsomn(:)    ! (gN/m2) total soil organic matter N

    ! fire related variables changed by F. Li and S. Levis
    real(rk8), pointer, contiguous :: m_leafn_to_fire(:)
    real(rk8), pointer, contiguous :: m_leafn_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_leafn_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_livestemn_to_fire(:)
    real(rk8), pointer, contiguous :: m_livestemn_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_livestemn_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemn_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemn_storage_to_fire(:)
    ! (gN/m2) total soil organic matter nitrogen to 1 meter
    real(rk8), pointer, contiguous :: totsomn_1m(:)
    real(rk8), pointer, contiguous :: m_deadcrootn_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootn_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadcrootn_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_deadstemn_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_frootn_to_fire(:)
    real(rk8), pointer, contiguous :: m_frootn_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_frootn_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootn_to_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootn_storage_to_fire(:)
    real(rk8), pointer, contiguous :: m_livecrootn_xfer_to_fire(:)
    real(rk8), pointer, contiguous :: m_retransn_to_fire(:)

    real(rk8), pointer, contiguous :: hrv_deadstemn_to_prod10n(:)
    real(rk8), pointer, contiguous :: hrv_deadstemn_to_prod100n(:)
    real(rk8), pointer, contiguous :: ndeploy(:)
    ! (gN/m2/s) total pft-level fire C loss
    real(rk8), pointer, contiguous :: pft_fire_nloss(:)
    real(rk8), pointer, contiguous :: retransn_to_npool(:)
    real(rk8), pointer, contiguous :: sminn_to_npool(:)
    real(rk8), pointer, contiguous :: deadcrootn(:)         ! (gN/m2) dead coarse root N
    real(rk8), pointer, contiguous :: deadcrootn_storage(:) ! (gN/m2) dead coas root N strg
    real(rk8), pointer, contiguous :: deadcrootn_xfer(:)    ! (gN/m2) dead cors root N trnf
    real(rk8), pointer, contiguous :: deadstemn(:)          ! (gN/m2) dead stem N
    real(rk8), pointer, contiguous :: deadstemn_storage(:)  ! (gN/m2) dead stem N storage
    real(rk8), pointer, contiguous :: deadstemn_xfer(:)     ! (gN/m2) dead stem N transfer
    ! (gN/m2) displayed veg nitrogen, excluding storage
    real(rk8), pointer, contiguous :: dispvegn(:)
    real(rk8), pointer, contiguous :: frootn(:)             ! (gN/m2) fine root N
    real(rk8), pointer, contiguous :: frootn_storage(:)     ! (gN/m2) fine root N storage
    real(rk8), pointer, contiguous :: frootn_xfer(:)        ! (gN/m2) fine root N transfer
    real(rk8), pointer, contiguous :: leafn(:)              ! (gN/m2) leaf N
    real(rk8), pointer, contiguous :: leafn_storage(:)      ! (gN/m2) leaf N storage
    real(rk8), pointer, contiguous :: leafn_xfer(:)         ! (gN/m2) leaf N transfer
    real(rk8), pointer, contiguous :: livecrootn(:)         ! (gN/m2) live coarse root N
    real(rk8), pointer, contiguous :: livecrootn_storage(:) ! (gN/m2) live cors root N strg
    real(rk8), pointer, contiguous :: livecrootn_xfer(:)    ! (gN/m2) live cors root N trnf
    real(rk8), pointer, contiguous :: grainn(:)             ! (gN/m2) grain N
    real(rk8), pointer, contiguous :: grainn_storage(:)     ! (gN/m2) grain N storage
    real(rk8), pointer, contiguous :: grainn_xfer(:)        ! (gN/m2) grain N transfer
    real(rk8), pointer, contiguous :: livestemn(:)          ! (gN/m2) live stem N
    real(rk8), pointer, contiguous :: livestemn_storage(:)  ! (gN/m2) live stem N storage
    real(rk8), pointer, contiguous :: livestemn_xfer(:)     ! (gN/m2) live stem N transfer
    real(rk8), pointer, contiguous :: retransn(:)           ! (gN/m2) plant pool of
                                                ! retranslocated N
    real(rk8), pointer, contiguous :: npool(:)      ! (gN/m2) temporary plant N pool
    real(rk8), pointer, contiguous :: pft_ntrunc(:) ! (gN/m2) pft-lev sink for N truncation
    real(rk8), pointer, contiguous :: storvegn(:)   ! (gN/m2) stored vegetation nitrogen
    real(rk8), pointer, contiguous :: totpftn(:)    ! (gN/m2) total pft-level nitrogen
    real(rk8), pointer, contiguous :: totvegn(:)    ! (gN/m2) total vegetation nitrogen
    ! for landcover change
    ! total N losses to wood product pools (gN/m2/s)
    real(rk8), pointer, contiguous :: wood_harvestn(:)
    ! (gN/m2/s) total nitrogen loss from product pools and conversion
    real(rk8), pointer, contiguous :: dwt_nloss(:)
    ! (gN/m2/s) conversion N flux (immediate loss to atm)
    real(rk8), pointer, contiguous :: dwt_conv_nflux(:)
    ! (gN/m2) column-level pool for seeding new PFTs
    real(rk8), pointer, contiguous :: seedn(:)
    ! (gN/m2/s) loss from 10-yr wood product pool
    real(rk8), pointer, contiguous :: prod10n_loss(:)
    ! (gN/m2/s) loss from 100-yr wood product pool
    real(rk8), pointer, contiguous :: prod100n_loss(:)
    ! (gN/m2/s) total wood product nitrogen loss
    real(rk8), pointer, contiguous :: product_nloss(:)
    ! (gN/m2) wood product N pool, 10-year lifespan
    real(rk8), pointer, contiguous :: prod10n(:)
    ! (gN/m2) wood product N pool, 100-year lifespan
    real(rk8), pointer, contiguous :: prod100n(:)
    ! (gN/m2) total wood product N
    real(rk8), pointer, contiguous :: totprodn(:)

    real(rk8), pointer, contiguous :: decomp_cascade_ntransfer_vr(:,:,:)
    real(rk8), pointer, contiguous :: decomp_cascade_ntransfer(:,:)
    ! vert-res mineral N flux for transition along decomposition
    ! cascade (gN/m3/s)
    real(rk8), pointer, contiguous :: decomp_cascade_sminn_flux_vr(:,:,:)
    ! vert-int (diagnostic) mineral N flux for transition along
    ! decomposition cascade (gN/m2/s)
    real(rk8), pointer, contiguous :: decomp_cascade_sminn_flux(:,:)

    ! total SOM N loss from vertical transport (gN/m^2/s)
    real(rk8), pointer, contiguous :: som_n_leached(:)
    ! N loss from vertical transport from each decomposing N pool (gN/m^2/s)
    real(rk8), pointer, contiguous :: decomp_npools_leached(:,:)
    ! N tendency due to vertical transport in decomposing N pools (gN/m^3/s)
    real(rk8), pointer, contiguous :: decomp_npools_transport_tendency(:,:,:)

    integer(ik4) :: c,p,j,k,l ! indices
    integer(ik4) :: fp,fc     ! lake filter indices
    real(rk8) :: maxdepth     ! depth to integrate soil variables

    ! assign local pointers
    ivt                        => clm3%g%l%c%p%itype
    col_fire_nloss             => clm3%g%l%c%cnf%col_fire_nloss
    denit                      => clm3%g%l%c%cnf%denit
    col_pft_fire_nloss         => clm3%g%l%c%cnf%pnf_a%pft_fire_nloss
    cwdn                       => clm3%g%l%c%cns%cwdn
    col_ntrunc                 => clm3%g%l%c%cns%col_ntrunc
    sminn                      => clm3%g%l%c%cns%sminn
    m_decomp_npools_to_fire_vr => clm3%g%l%c%cnf%m_decomp_npools_to_fire_vr
    m_decomp_npools_to_fire    => clm3%g%l%c%cnf%m_decomp_npools_to_fire
    is_litter                  => decomp_cascade_con%is_litter
    is_soil                    => decomp_cascade_con%is_soil
    is_cwd                     => decomp_cascade_con%is_cwd
#ifndef NITRIF_DENITRIF
    sminn_to_denit_excess_vr   => clm3%g%l%c%cnf%sminn_to_denit_excess_vr
    sminn_to_denit_excess      => clm3%g%l%c%cnf%sminn_to_denit_excess
    sminn_to_denit_decomp_cascade_vr &
            => clm3%g%l%c%cnf%sminn_to_denit_decomp_cascade_vr
    sminn_to_denit_decomp_cascade    => &
            clm3%g%l%c%cnf%sminn_to_denit_decomp_cascade
    sminn_leached_vr       => clm3%g%l%c%cnf%sminn_leached_vr
    sminn_leached          => clm3%g%l%c%cnf%sminn_leached
#else
    smin_no3               => clm3%g%l%c%cns%smin_no3
    smin_nh4               => clm3%g%l%c%cns%smin_nh4
    smin_no3_vr            => clm3%g%l%c%cns%smin_no3_vr
    smin_nh4_vr            => clm3%g%l%c%cns%smin_nh4_vr
    f_nit_vr               => clm3%g%l%c%cnf%f_nit_vr
    f_nit                  => clm3%g%l%c%cnf%f_nit
    f_denit_vr             => clm3%g%l%c%cnf%f_denit_vr
    f_denit                => clm3%g%l%c%cnf%f_denit
    pot_f_nit_vr           => clm3%g%l%c%cnf%pot_f_nit_vr
    pot_f_nit              => clm3%g%l%c%cnf%pot_f_nit
    pot_f_denit_vr         => clm3%g%l%c%cnf%pot_f_denit_vr
    pot_f_denit            => clm3%g%l%c%cnf%pot_f_denit
    f_n2o_denit_vr         => clm3%g%l%c%cnf%f_n2o_denit_vr
    f_n2o_nit_vr           => clm3%g%l%c%cnf%f_n2o_nit_vr
    f_n2o_denit            => clm3%g%l%c%cnf%f_n2o_denit
    f_n2o_nit              => clm3%g%l%c%cnf%f_n2o_nit
    f_n2o_tot              => clm3%g%l%c%cnf%f_n2o_tot
    f_n2o_tot_vr           => clm3%g%l%c%cnf%f_n2o_tot_vr
    smin_no3_leached_vr    => clm3%g%l%c%cnf%smin_no3_leached_vr
    smin_no3_leached       => clm3%g%l%c%cnf%smin_no3_leached
    smin_no3_runoff_vr     => clm3%g%l%c%cnf%smin_no3_runoff_vr
    smin_no3_runoff        => clm3%g%l%c%cnf%smin_no3_runoff
#endif
    decomp_npools            => clm3%g%l%c%cns%decomp_npools
    decomp_npools_vr         => clm3%g%l%c%cns%decomp_npools_vr
    decomp_npools_1m         => clm3%g%l%c%cns%decomp_npools_1m
    altmax_indx              => clm3%g%l%c%cps%altmax_indx
    altmax_lastyear_indx     => clm3%g%l%c%cps%altmax_lastyear_indx
    sminn_vr                 => clm3%g%l%c%cns%sminn_vr
    col_ntrunc_vr            => clm3%g%l%c%cns%col_ntrunc_vr
    supplement_to_sminn      => clm3%g%l%c%cnf%supplement_to_sminn
    supplement_to_sminn_vr   => clm3%g%l%c%cnf%supplement_to_sminn_vr
    col_totpftn              => clm3%g%l%c%cns%pns_a%totpftn
    col_totvegn              => clm3%g%l%c%cns%pns_a%totvegn
    totcoln                  => clm3%g%l%c%cns%totcoln
    totecosysn               => clm3%g%l%c%cns%totecosysn
    totlitn                  => clm3%g%l%c%cns%totlitn
    totlitn_1m               => clm3%g%l%c%cns%totlitn_1m
    totsomn                  => clm3%g%l%c%cns%totsomn
    m_leafn_to_fire          => clm3%g%l%c%p%pnf%m_leafn_to_fire
    m_leafn_storage_to_fire  => clm3%g%l%c%p%pnf%m_leafn_storage_to_fire
    m_leafn_xfer_to_fire     => clm3%g%l%c%p%pnf%m_leafn_xfer_to_fire
    m_livestemn_to_fire      => clm3%g%l%c%p%pnf%m_livestemn_to_fire
    m_livestemn_storage_to_fire => clm3%g%l%c%p%pnf%m_livestemn_storage_to_fire
    m_livestemn_xfer_to_fire    => clm3%g%l%c%p%pnf%m_livestemn_xfer_to_fire
    m_deadstemn_to_fire      => clm3%g%l%c%p%pnf%m_deadstemn_to_fire
    totsomn_1m               => clm3%g%l%c%cns%totsomn_1m
    m_deadcrootn_storage_to_fire => &
            clm3%g%l%c%p%pnf%m_deadcrootn_storage_to_fire
    m_deadcrootn_to_fire         => clm3%g%l%c%p%pnf%m_deadcrootn_to_fire
    m_deadcrootn_xfer_to_fire    => clm3%g%l%c%p%pnf%m_deadcrootn_xfer_to_fire
    m_deadstemn_storage_to_fire  => &
            clm3%g%l%c%p%pnf%m_deadstemn_storage_to_fire
    m_deadstemn_xfer_to_fire     => clm3%g%l%c%p%pnf%m_deadstemn_xfer_to_fire
    m_frootn_to_fire             => clm3%g%l%c%p%pnf%m_frootn_to_fire
    m_frootn_storage_to_fire     => clm3%g%l%c%p%pnf%m_frootn_storage_to_fire
    m_frootn_xfer_to_fire        => clm3%g%l%c%p%pnf%m_frootn_xfer_to_fire
    m_livecrootn_to_fire         => clm3%g%l%c%p%pnf%m_livecrootn_to_fire
    m_livecrootn_storage_to_fire => &
            clm3%g%l%c%p%pnf%m_livecrootn_storage_to_fire
    m_livecrootn_xfer_to_fire    => clm3%g%l%c%p%pnf%m_livecrootn_xfer_to_fire
    m_deadcrootn_to_fire         => clm3%g%l%c%p%pnf%m_deadcrootn_to_fire
    m_deadcrootn_storage_to_fire => &
            clm3%g%l%c%p%pnf%m_deadcrootn_storage_to_fire
    m_deadcrootn_xfer_to_fire    => clm3%g%l%c%p%pnf%m_deadcrootn_xfer_to_fire
    m_retransn_to_fire           => clm3%g%l%c%p%pnf%m_retransn_to_fire

    hrv_deadstemn_to_prod10n     => clm3%g%l%c%p%pnf%hrv_deadstemn_to_prod10n
    hrv_deadstemn_to_prod100n    => clm3%g%l%c%p%pnf%hrv_deadstemn_to_prod100n
    ndeploy                      => clm3%g%l%c%p%pnf%ndeploy
    pft_fire_nloss               => clm3%g%l%c%p%pnf%pft_fire_nloss
    retransn_to_npool            => clm3%g%l%c%p%pnf%retransn_to_npool
    sminn_to_npool               => clm3%g%l%c%p%pnf%sminn_to_npool
    deadcrootn                   => clm3%g%l%c%p%pns%deadcrootn
    deadcrootn_storage           => clm3%g%l%c%p%pns%deadcrootn_storage
    deadcrootn_xfer              => clm3%g%l%c%p%pns%deadcrootn_xfer
    deadstemn                    => clm3%g%l%c%p%pns%deadstemn
    deadstemn_storage            => clm3%g%l%c%p%pns%deadstemn_storage
    deadstemn_xfer               => clm3%g%l%c%p%pns%deadstemn_xfer
    dispvegn                     => clm3%g%l%c%p%pns%dispvegn
    frootn                       => clm3%g%l%c%p%pns%frootn
    frootn_storage               => clm3%g%l%c%p%pns%frootn_storage
    frootn_xfer                  => clm3%g%l%c%p%pns%frootn_xfer
    leafn                        => clm3%g%l%c%p%pns%leafn
    leafn_storage                => clm3%g%l%c%p%pns%leafn_storage
    leafn_xfer                   => clm3%g%l%c%p%pns%leafn_xfer
    livecrootn                   => clm3%g%l%c%p%pns%livecrootn
    livecrootn_storage           => clm3%g%l%c%p%pns%livecrootn_storage
    livecrootn_xfer              => clm3%g%l%c%p%pns%livecrootn_xfer
    grainn                       => clm3%g%l%c%p%pns%grainn
    grainn_storage               => clm3%g%l%c%p%pns%grainn_storage
    grainn_xfer                  => clm3%g%l%c%p%pns%grainn_xfer
    livestemn                    => clm3%g%l%c%p%pns%livestemn
    livestemn_storage            => clm3%g%l%c%p%pns%livestemn_storage
    livestemn_xfer               => clm3%g%l%c%p%pns%livestemn_xfer
    retransn                     => clm3%g%l%c%p%pns%retransn
    npool                        => clm3%g%l%c%p%pns%npool
    pft_ntrunc                   => clm3%g%l%c%p%pns%pft_ntrunc
    storvegn                     => clm3%g%l%c%p%pns%storvegn
    totpftn                      => clm3%g%l%c%p%pns%totpftn
    totvegn                      => clm3%g%l%c%p%pns%totvegn
    ! dynamic landcover pointers
    wood_harvestn                => clm3%g%l%c%p%pnf%wood_harvestn
    col_wood_harvestn            => clm3%g%l%c%cnf%pnf_a%wood_harvestn
    dwt_nloss                    => clm3%g%l%c%cnf%dwt_nloss
    dwt_conv_nflux               => clm3%g%l%c%cnf%dwt_conv_nflux
    prod10n_loss                 => clm3%g%l%c%cnf%prod10n_loss
    prod100n_loss                => clm3%g%l%c%cnf%prod100n_loss
    product_nloss                => clm3%g%l%c%cnf%product_nloss
    seedn                        => clm3%g%l%c%cns%seedn
    prod10n                      => clm3%g%l%c%cns%prod10n
    prod100n                     => clm3%g%l%c%cns%prod100n
    totprodn                     => clm3%g%l%c%cns%totprodn
    som_n_leached                => clm3%g%l%c%cnf%som_n_leached
    decomp_npools_leached        => clm3%g%l%c%cnf%decomp_npools_leached
    decomp_npools_transport_tendency => &
            clm3%g%l%c%cnf%decomp_npools_transport_tendency
    decomp_cascade_ntransfer_vr  => clm3%g%l%c%cnf%decomp_cascade_ntransfer_vr
    decomp_cascade_ntransfer     => clm3%g%l%c%cnf%decomp_cascade_ntransfer
    decomp_cascade_sminn_flux_vr => clm3%g%l%c%cnf%decomp_cascade_sminn_flux_vr
    decomp_cascade_sminn_flux    => clm3%g%l%c%cnf%decomp_cascade_sminn_flux

    ! pft loop
    do fp = 1, num_soilp
      p = filter_soilp(fp)

      ! calculate pft-level summary nitrogen fluxes and states

      ! total N deployment (from sminn and retranslocated N pool) (NDEPLOY)
      ndeploy(p) = &
         sminn_to_npool(p) + &
         retransn_to_npool(p)

      ! pft-level wood harvest
      wood_harvestn(p) = &
         hrv_deadstemn_to_prod10n(p) + &
         hrv_deadstemn_to_prod100n(p)

      ! total pft-level fire N losses
      pft_fire_nloss(p) = &
         m_leafn_to_fire(p)               + &
         m_leafn_storage_to_fire(p)       + &
         m_leafn_xfer_to_fire(p)          + &
         m_frootn_to_fire(p)              + &
         m_frootn_storage_to_fire(p)      + &
         m_frootn_xfer_to_fire(p)         + &
         m_livestemn_to_fire(p)           + &
         m_livestemn_storage_to_fire(p)   + &
         m_livestemn_xfer_to_fire(p)      + &
         m_deadstemn_to_fire(p)           + &
         m_deadstemn_storage_to_fire(p)   + &
         m_deadstemn_xfer_to_fire(p)      + &
         m_livecrootn_to_fire(p)          + &
         m_livecrootn_storage_to_fire(p)  + &
         m_livecrootn_xfer_to_fire(p)     + &
         m_deadcrootn_to_fire(p)          + &
         m_deadcrootn_storage_to_fire(p)  + &
         m_deadcrootn_xfer_to_fire(p)     + &
         m_retransn_to_fire(p)

      ! displayed vegetation nitrogen, excluding storage (DISPVEGN)
      dispvegn(p) = &
         leafn(p)      + &
         frootn(p)     + &
         livestemn(p)  + &
         deadstemn(p)  + &
         livecrootn(p) + &
         deadcrootn(p)

      ! stored vegetation nitrogen, including retranslocated N pool (STORVEGN)
      storvegn(p) = &
         leafn_storage(p)      + &
         frootn_storage(p)     + &
         livestemn_storage(p)  + &
         deadstemn_storage(p)  + &
         livecrootn_storage(p) + &
         deadcrootn_storage(p) + &
         leafn_xfer(p)         + &
         frootn_xfer(p)        + &
         livestemn_xfer(p)     + &
         deadstemn_xfer(p)     + &
         livecrootn_xfer(p)    + &
         deadcrootn_xfer(p)    + &
         npool(p)              + &
         retransn(p)

      if ( crop_prog .and. ivt(p) >= npcropmin ) then
        dispvegn(p) = dispvegn(p) + &
            grainn(p)
        storvegn(p) = storvegn(p) + &
             grainn_storage(p)     + &
             grainn_xfer(p)
      end if

      ! total vegetation nitrogen (TOTVEGN)
      totvegn(p) = dispvegn(p) + storvegn(p)

      ! total pft-level carbon (add pft_ntrunc)
      totpftn(p) = totvegn(p) + pft_ntrunc(p)

     end do  ! end of pfts loop

    ! use p2c routine to get selected column-average pft-level fluxes and states
    call p2c(num_soilc, filter_soilc, pft_fire_nloss, col_pft_fire_nloss)
    call p2c(num_soilc, filter_soilc, wood_harvestn, col_wood_harvestn)
    call p2c(num_soilc, filter_soilc, totvegn, col_totvegn)
    call p2c(num_soilc, filter_soilc, totpftn, col_totpftn)

    ! column loops
    do fc = 1, num_soilc
      c = filter_soilc(fc)

      ! some zeroing
      denit(c) = 0._rk8
#ifdef NITRIF_DENITRIF
      smin_no3(c) = 0._rk8
      smin_nh4(c) = 0._rk8
#endif
      totlitn(c) = 0._rk8
      totsomn(c) = 0._rk8
      cwdn(c) = 0._rk8
      sminn(c) = 0._rk8
      col_ntrunc(c) = 0._rk8
      supplement_to_sminn(c) = 0._rk8
      som_n_leached(c) = 0._rk8
      totlitn_1m(c) = 0._rk8
      totsomn_1m(c) = 0._rk8
    end do

    ! vertically integrate decomposing N cascade fluxes and soil mineral
    ! N fluxes associated with decomposition cascade
    do k = 1, ndecomp_cascade_transitions
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_cascade_ntransfer(c,k) = decomp_cascade_ntransfer(c,k) + &
                  decomp_cascade_ntransfer_vr(c,j,k) * dzsoi_decomp(j)
          decomp_cascade_sminn_flux(c,k) = decomp_cascade_sminn_flux(c,k) + &
                  decomp_cascade_sminn_flux_vr(c,j,k) * dzsoi_decomp(j)
        end do
      end do
    end do

#ifndef NITRIF_DENITRIF
    ! vertically integrate each denitrification flux
    do l = 1, ndecomp_cascade_transitions
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          sminn_to_denit_decomp_cascade(c,l) = &
                  sminn_to_denit_decomp_cascade(c,l) + &
                  sminn_to_denit_decomp_cascade_vr(c,j,l) * dzsoi_decomp(j)
        end do
      end do
    end do

    ! vertically integrate bulk denitrification and  leaching flux
    do j = 1, nlevdecomp
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        sminn_to_denit_excess(c) = sminn_to_denit_excess(c) + &
                sminn_to_denit_excess_vr(c,j) * dzsoi_decomp(j)
        sminn_leached(c) = sminn_leached(c) + sminn_leached_vr(c,j) * &
                dzsoi_decomp(j)
      end do
    end do

    ! total N denitrification (DENIT)
    do l = 1, ndecomp_cascade_transitions
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        denit(c) = denit(c) + sminn_to_denit_decomp_cascade(c,l)
      end do
    end do

    do fc = 1, num_soilc
      c = filter_soilc(fc)
      denit(c) =  denit(c) + sminn_to_denit_excess(c)
    end do

#else

    ! vertically integrate NO3 NH4 N2O fluxes and pools
    do j = 1, nlevdecomp
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        ! nitrification and denitrification fluxes
        f_nit(c) = f_nit(c) + f_nit_vr(c,j) * dzsoi_decomp(j)
        f_denit(c) = f_denit(c) + f_denit_vr(c,j) * dzsoi_decomp(j)
        pot_f_nit(c) = pot_f_nit(c) + pot_f_nit_vr(c,j) * dzsoi_decomp(j)
        pot_f_denit(c) = pot_f_denit(c) + pot_f_denit_vr(c,j) * dzsoi_decomp(j)
        f_n2o_nit(c) = f_n2o_nit(c) + f_n2o_nit_vr(c,j) * dzsoi_decomp(j)
        f_n2o_denit(c) = f_n2o_denit(c) + f_n2o_denit_vr(c,j) * dzsoi_decomp(j)

        ! samy : Total soil N2O emission to atmosphere
        f_n2o_tot(c) = f_n2o_tot(c) + f_n2o_tot_vr(c,j) * dzsoi_decomp(j)

        ! leaching/runoff flux
        smin_no3_leached(c) = smin_no3_leached(c) + &
                smin_no3_leached_vr(c,j) * dzsoi_decomp(j)
        smin_no3_runoff(c) = smin_no3_runoff(c) + &
                smin_no3_runoff_vr(c,j) * dzsoi_decomp(j)

        ! mineral N pools (must set to zero first since they are state
        ! rather than flux variables)
        smin_no3(c) = smin_no3(c) + smin_no3_vr(c,j) * dzsoi_decomp(j)
        smin_nh4(c) = smin_nh4(c) + smin_nh4_vr(c,j) * dzsoi_decomp(j)
      end do
    end do

    do fc = 1, num_soilc
      c = filter_soilc(fc)
      denit(c) = f_denit(c)
    end do

#endif

    ! vertically integrate column-level fire N losses
    do k = 1, ndecomp_pools
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          m_decomp_npools_to_fire(c,k) = m_decomp_npools_to_fire(c,k) + &
                 m_decomp_npools_to_fire_vr(c,j,k) * dzsoi_decomp(j)
        end do
      end do
    end do

    ! total column-level fire N losses
    do fc = 1, num_soilc
      c = filter_soilc(fc)
      col_fire_nloss(c) = col_pft_fire_nloss(c)
    end do
    do k = 1, ndecomp_pools
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        col_fire_nloss(c) = col_fire_nloss(c) + &
              m_decomp_npools_to_fire(c,k)
      end do
    end do

    ! vertically integrate each of the decomposing N pools
    do l = 1, ndecomp_pools
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        decomp_npools(c,l) = 0._rk8
      end do
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_npools(c,l) = decomp_npools(c,l) + &
                 decomp_npools_vr(c,j,l) * dzsoi_decomp(j)
        end do
      end do
    end do

    ! for vertically-resolved soil biogeochemistry, calculate some
    ! diagnostics of carbon pools to a given depth
    if ( nlevdecomp > 1 ) then

      do l = 1, ndecomp_pools
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_npools_1m(c,l) = 0._rk8
        end do
      end do

      ! vertically integrate each of the decomposing n pools to 1 meter
      maxdepth = 1._rk8
      do l = 1, ndecomp_pools
        do j = 1, nlevdecomp
          if ( zisoi(j) <= maxdepth ) then
            do fc = 1, num_soilc
              c = filter_soilc(fc)
              decomp_npools_1m(c,l) = decomp_npools_1m(c,l) + &
                       decomp_npools_vr(c,j,l) * dzsoi_decomp(j)
            end do
          else if ( zisoi(j-1) < maxdepth ) then
            do fc = 1, num_soilc
              c = filter_soilc(fc)
              decomp_npools_1m(c,l) = decomp_npools_1m(c,l) + &
                       decomp_npools_vr(c,j,l) * (maxdepth - zisoi(j-1))
            end do
          end if
        end do
      end do

      ! total litter nitrogen to 1 meter (TOTLITN_1m)
      do l = 1, ndecomp_pools
        if ( is_litter(l) ) then
          do fc = 1, num_soilc
            c = filter_soilc(fc)
            totlitn_1m(c) = totlitn_1m(c) + decomp_npools_1m(c,l)
          end do
        end if
      end do

      ! total soil organic matter nitrogen to 1 meter (TOTSOMN_1m)
      do l = 1, ndecomp_pools
        if ( is_soil(l) ) then
          do fc = 1, num_soilc
            c = filter_soilc(fc)
            totsomn_1m(c) = totsomn_1m(c) + decomp_npools_1m(c,l)
          end do
        end if
      end do
    endif

    ! total litter nitrogen (TOTLITN)
    do l = 1, ndecomp_pools
      if ( is_litter(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          totlitn(c) = totlitn(c) + decomp_npools(c,l)
        end do
      end if
    end do

    ! total soil organic matter nitrogen (TOTSOMN)
    do l = 1, ndecomp_pools
      if ( is_soil(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          totsomn(c) = totsomn(c) + decomp_npools(c,l)
        end do
      end if
    end do

    ! total cwdn
    do l = 1, ndecomp_pools
      if ( is_cwd(l) ) then
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          cwdn(c) = cwdn(c) + decomp_npools(c,l)
        end do
      end if
    end do

    ! total sminn
    do j = 1, nlevdecomp
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        sminn(c) = sminn(c) + sminn_vr(c,j) * dzsoi_decomp(j)
      end do
    end do

    ! total col_ntrunc
    do j = 1, nlevdecomp
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        col_ntrunc(c) = col_ntrunc(c) + col_ntrunc_vr(c,j) * dzsoi_decomp(j)
      end do
    end do

    ! supplementary N supplement_to_sminn
    do j = 1, nlevdecomp
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        supplement_to_sminn(c) = supplement_to_sminn(c) + &
              supplement_to_sminn_vr(c,j) * dzsoi_decomp(j)
      end do
    end do

    do fc = 1, num_soilc
      c = filter_soilc(fc)

      ! column-level N losses due to landcover change
      dwt_nloss(c) = dwt_conv_nflux(c)

      ! total wood product N loss
      product_nloss(c) = &
         prod10n_loss(c) + &
         prod100n_loss(c)

      ! total wood product nitrogen
      totprodn(c) = prod10n(c) + prod100n(c)

      ! total ecosystem nitrogen, including veg (TOTECOSYSN)
      totecosysn(c) = &
         cwdn(c) + &
         totlitn(c) + &
         totsomn(c) + &
         sminn(c) + &
         totprodn(c) + &
         col_totvegn(c)

      ! total column nitrogen, including pft (TOTCOLN)
      totcoln(c) = &
         col_totpftn(c) + &
         cwdn(c) + &
         totlitn(c) + &
         totsomn(c) + &
         sminn(c) + &
         totprodn(c) + &
         seedn(c) + &
         col_ntrunc(c)
    end do

    ! add up all vertical transport tendency terms and calculate
    ! total som leaching loss as the sum of these
    do l = 1, ndecomp_pools
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        decomp_npools_leached(c,l) = 0._rk8
      end do
      do j = 1, nlevdecomp
        do fc = 1, num_soilc
          c = filter_soilc(fc)
          decomp_npools_leached(c,l) = decomp_npools_leached(c,l) + &
                  decomp_npools_transport_tendency(c,j,l) * dzsoi_decomp(j)
        end do
      end do
      do fc = 1, num_soilc
        c = filter_soilc(fc)
        som_n_leached(c) = som_n_leached(c) + decomp_npools_leached(c,l)
      end do
    end do
  end subroutine NSummary

#endif

end module mod_clm_cnsummary
! vim: tabstop=8 expandtab shiftwidth=2 softtabstop=2
